Class: WorldTradeDataQuote
- Inherits:
-
Object
- Object
- WorldTradeDataQuote
- 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.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exchange ⇒ Object
readonly
Returns the value of attribute exchange.
-
#high ⇒ Object
readonly
Returns the value of attribute high.
-
#low ⇒ Object
readonly
Returns the value of attribute low.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#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
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) ⇒ WorldTradeDataQuote
constructor
A new instance of WorldTradeDataQuote.
Constructor Details
#initialize(json_blob) ⇒ WorldTradeDataQuote
Returns a new instance of WorldTradeDataQuote.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 74 def initialize(json_blob) Lita.logger.debug "parsing: #{json_blob}" hash = JSON.parse(json_blob) if hash['Message'].to_s.include? 'Error' @error = true return else @error = false end quote = hash['data'][0] quote.keys.each do |key| case key when "symbol" @symbol = quote[key] when "price_open" @open = self.fix_number quote[key] when "day_high" @high = self.fix_number quote[key] when "day_low" @low = self.fix_number quote[key] when "price" @price = self.fix_number quote[key] when "volume" @volume = quote[key].to_i when "last_trade_time" @trading_day = quote[key] when "08. previous close" @prev_close = self.fix_number quote[key] when "day_change" @change = self.fix_number quote[key] when "change_pct" @change_percent = self.fix_number quote[key] when 'stock_exchange_short' @exchange = quote[key].sub /NYSEARCA/, 'NYSE' when 'name' @name = quote[key] end end end |
Instance Attribute Details
#change ⇒ Object (readonly)
Returns the value of attribute change.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def change @change end |
#change_percent ⇒ Object (readonly)
Returns the value of attribute change_percent.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def change_percent @change_percent end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def error @error end |
#exchange ⇒ Object (readonly)
Returns the value of attribute exchange.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def exchange @exchange end |
#high ⇒ Object (readonly)
Returns the value of attribute high.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def high @high end |
#low ⇒ Object (readonly)
Returns the value of attribute low.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def low @low end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def name @name end |
#open ⇒ Object (readonly)
Returns the value of attribute open.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def open @open end |
#prev_close ⇒ Object (readonly)
Returns the value of attribute prev_close.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def prev_close @prev_close end |
#price ⇒ Object (readonly)
Returns the value of attribute price.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def price @price end |
#symbol ⇒ Object
Returns the value of attribute symbol.
72 73 74 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 72 def symbol @symbol end |
#trading_day ⇒ Object (readonly)
Returns the value of attribute trading_day.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def trading_day @trading_day end |
#volume ⇒ Object (readonly)
Returns the value of attribute volume.
71 72 73 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 71 def volume @volume end |
Instance Method Details
#fix_number(price_str) ⇒ Object
117 118 119 |
# File 'lib/lita/handlers/onewheel_finance.rb', line 117 def fix_number(price_str) price_str.to_f.round(2) end |