Class: Flipit::App
- Inherits:
-
Object
- Object
- Flipit::App
- Defined in:
- lib/flipit/app.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
Instance Method Summary collapse
-
#initialize(args, output = STDOUT, error = STDERR) ⇒ App
constructor
A new instance of App.
- #pbcopy(string) ⇒ Object
- #run ⇒ Object
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. = "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
#args ⇒ Object (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 |
#run ⇒ Object
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 |