Class: AlphaVantageQuote

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) ⇒ 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

#changeObject (readonly)

Returns the value of attribute change.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def change
  @change
end

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

#highObject (readonly)

Returns the value of attribute high.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def high
  @high
end

#lowObject (readonly)

Returns the value of attribute low.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def low
  @low
end

#openObject (readonly)

Returns the value of attribute open.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def open
  @open
end

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

#priceObject (readonly)

Returns the value of attribute price.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def price
  @price
end

#symbolObject (readonly)

Returns the value of attribute symbol.



32
33
34
# File 'lib/lita/handlers/onewheel_finance.rb', line 32

def symbol
  @symbol
end

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

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