Class: Flipit::App

Inherits:
Object
  • Object
show all
Defined in:
lib/flipit/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args, output = STDOUT, error = STDERR) ⇒ App

Returns a new instance of App.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/flipit/app.rb', line 7

def initialize(args, output=STDOUT, error=STDERR)
  @args = args
  @output = output
  @error = error
  @print = false

  parser = OptionParser.new do |parser|
    parser.banner = "USAGE: flipit [options] [text ...]"
    parser.separator ''
    parser.separator 'Options:'
    parser.on '-p', '--print' do
      @print = true
    end
  end
  parser.parse!(args)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



24
25
26
# File 'lib/flipit/app.rb', line 24

def args
  @args
end

Instance Method Details

#pbcopy(string) ⇒ Object



41
42
43
44
45
# File 'lib/flipit/app.rb', line 41

def pbcopy(string)
  Open3.popen2('pbcopy') do |stdin, stdout, wait_thread|
    stdin.print string
  end
end

#runObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/flipit/app.rb', line 26

def run
  if args.empty?
    flipped = "#{flipper} #{table}"
  elsif
    text = args.join(' ')
    flipped = "#{flipper} #{flip(text)}"
  end
  if @print
    @output.puts flipped
  else
    pbcopy(flipped)
  end
  0
end