Class: AlphaVantageQuote
- Inherits:
-
Object
- Object
- AlphaVantageQuote
- Defined in:
- lib/lita/handlers/onewheel_finance.rb
Instance Attribute Summary collapse
-
#change ⇒ Object
readonly
Returns the value of attribute change.
-
#change_percent ⇒ Object
readonly
Returns the value of attribute change_percent.
-
#high ⇒ Object
readonly
Returns the value of attribute high.
-
#low ⇒ Object
readonly
Returns the value of attribute low.
-
#open ⇒ Object
readonly
Returns the value of attribute open.
-
#prev_close ⇒ Object
readonly
Returns the value of attribute prev_close.
-
#price ⇒ Object
readonly
Returns the value of attribute price.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
-
#trading_day ⇒ Object
readonly
Returns the value of attribute trading_day.
-
#volume ⇒ Object
readonly
Returns the value of attribute volume.
Instance Method Summary collapse
- #fix_number(price_str) ⇒ Object
-
#initialize(json_blob) ⇒ AlphaVantageQuote
constructor
A new instance of AlphaVantageQuote.
Constructor Details
#initialize(json_blob) ⇒ AlphaVantageQuote
Returns a new instance of AlphaVantageQuote.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 34 def initialize(json_blob) Lita.logger.debug "parsing: #{json_blob}" hash = JSON.parse(json_blob) quote = hash["Global Quote"] quote.keys.each do |key| case key when "01. symbol" @symbol = quote[key] when "02. open" @open = self.fix_number quote[key] when "03. high" @high = self.fix_number quote[key] when "04. low" @low = self.fix_number quote[key] when "05. price" @price = self.fix_number quote[key] when "06. volume" @volume = quote[key] when "07. latest trading day" @trading_day = quote[key] when "08. previous close" @prev_close = self.fix_number quote[key] when "09. change" @change = self.fix_number quote[key] when "10. change percent" @change_percent = self.fix_number quote[key] end end end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def change @change end |
#change_percent ⇒ Object (readonly)
Returns the value of attribute change_percent.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def change_percent @change_percent end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def high @high end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def low @low end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def open @open end |
#prev_close ⇒ Object (readonly)
Returns the value of attribute prev_close.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def prev_close @prev_close end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def price @price end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def symbol @symbol end |
#trading_day ⇒ Object (readonly)
Returns the value of attribute trading_day.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def trading_day @trading_day end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
32 33 34 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 32 def volume @volume end |
Instance Method Details
#fix_number(price_str) ⇒ Object
65 66 67 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 65 def fix_number(price_str) price_str.to_f.round(2) end |