Class: Stockery::Runner
- Inherits:
-
Object
- Object
- Stockery::Runner
- Defined in:
- lib/stockery/runner.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(argv) ⇒ Runner
constructor
A new instance of Runner.
- #run! ⇒ Object
Constructor Details
#initialize(argv) ⇒ Runner
Returns a new instance of Runner.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/stockery/runner.rb', line 7 def initialize(argv) @argv = argv # Default options values = { :source => Stockery::GOOGLE, :quotes => '', :output => 'json', } parse! end |
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
5 6 7 |
# File 'lib/stockery/runner.rb', line 5 def end |
Instance Method Details
#run! ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/stockery/runner.rb', line 20 def run! if [:quotes].length == 0 abort "Stock symbols missing. Usage `stockery -q \"GOOG, MSFT\"" end s_q = Stockery::Quote.new s_q.source = [:source] quotes = [:quotes].split(',').collect { |q| q.to_s.strip } quotes_res = [] quotes.each do |quote| quotes_res << s_q.get_status(quote) end case [:output] when 'print' puts "Quotes at #{Time.now}\n" puts "" quotes_res.each do |quote| puts s_q.print(quote) puts "\n" end when 'json' puts JSON.generate(quotes_res) end end |