class Expd::Expander

Public Class Methods

new(snippets) click to toggle source
# File lib/expd/expander.rb, line 3
def initialize(snippets)
  @snippets = snippets
end

Public Instance Methods

expand(name, opts = {}) click to toggle source
# File lib/expd/expander.rb, line 7
def expand(name, opts = {})
  exp = @snippets.fetch(name, "").chomp
  copy_to_clipboard exp if opts[:copy] && !exp.empty?
  exp
end

Private Instance Methods

clipboard_cmd() click to toggle source
# File lib/expd/expander.rb, line 19
def clipboard_cmd
  @expand_cmd ||=
    case RUBY_PLATFORM
    when /darwin/
      "pbcopy"
    # I dunno what to use on Windows
    else
      "xclip -i"
    end
end
copy_to_clipboard(text) click to toggle source
# File lib/expd/expander.rb, line 15
def copy_to_clipboard(text)
  IO.popen(clipboard_cmd, "w") { |p| p.write text } unless text.empty?
end