Class: MarkIt::Quote

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/markit.rb

Overview

To use, initialize with MarkIt::Quote.new(ticker) where ticker is a string of the company’s trading symbol e.g. aapl = MarkIt::Quote.new(“AAPL”)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticker) ⇒ Quote

ticker is a string of the company’s trading symbol



30
31
32
33
34
35
36
# File 'lib/markit.rb', line 30

def initialize(ticker) #ticker is a string of the company's trading symbol
  self.ticker = ticker
  self.info = self.class.get("symbol=#{ticker}") #GET method
  if self.info["Error"]
    self.info = "Error. Please enter a new ticker."
  end
end

Instance Attribute Details

#infoObject

Returns the value of attribute info.



26
27
28
# File 'lib/markit.rb', line 26

def info
  @info
end

#tickerObject

Returns the value of attribute ticker.



26
27
28
# File 'lib/markit.rb', line 26

def ticker
  @ticker
end

Instance Method Details

#change_ytdObject



46
47
48
# File 'lib/markit.rb', line 46

def change_ytd
  (last_price.to_f - info["QuoteApiModel"]["Data"]["ChangeYTD"].to_f).to_s
end