Class: WorldTradeDataQuote

Inherits:
Object
  • Object
show all
Defined in:
lib/lita/handlers/onewheel_finance.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#changeObject (readonly)

Returns the value of attribute change.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def change
  @change
end

#change_percentObject (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

#errorObject (readonly)

Returns the value of attribute error.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def error
  @error
end

#exchangeObject (readonly)

Returns the value of attribute exchange.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def exchange
  @exchange
end

#highObject (readonly)

Returns the value of attribute high.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def high
  @high
end

#lowObject (readonly)

Returns the value of attribute low.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def low
  @low
end

#nameObject (readonly)

Returns the value of attribute name.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def name
  @name
end

#openObject (readonly)

Returns the value of attribute open.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def open
  @open
end

#prev_closeObject (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

#priceObject (readonly)

Returns the value of attribute price.



71
72
73
# File 'lib/lita/handlers/onewheel_finance.rb', line 71

def price
  @price
end

#symbolObject

Returns the value of attribute symbol.



72
73
74
# File 'lib/lita/handlers/onewheel_finance.rb', line 72

def symbol
  @symbol
end

#trading_dayObject (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

#volumeObject (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