Class: YahooFinance::PastQuote
- Inherits:
-
Object
- Object
- YahooFinance::PastQuote
- Defined in:
- lib/stocktracker/yahoofinance.rb
Constant Summary collapse
- PAST_FORMAT =
[ :date, [:open,"to_f"], [:high,"to_f"], [:low,"to_f"], [:close,"to_f"], [:volume,"to_f"], [:adj_close,"to_f"] ]
Instance Attribute Summary collapse
-
#end_date ⇒ Object
Returns the value of attribute end_date.
-
#results ⇒ Object
Returns the value of attribute results.
-
#start_date ⇒ Object
Returns the value of attribute start_date.
-
#symbol ⇒ Object
Returns the value of attribute symbol.
Instance Method Summary collapse
- #get_past_quote ⇒ Object
-
#initialize(symbol, date) ⇒ PastQuote
constructor
A new instance of PastQuote.
- #past_map ⇒ Object
- #past_values ⇒ Object
- #yahoo_past_quote ⇒ Object
- #yahoo_past_url ⇒ Object
Constructor Details
#initialize(symbol, date) ⇒ PastQuote
Returns a new instance of PastQuote.
100 101 102 103 104 105 |
# File 'lib/stocktracker/yahoofinance.rb', line 100 def initialize(symbol, date) self.symbol= symbol self.start_date= date self.end_date= date self.results= get_past_quote end |
Instance Attribute Details
#end_date ⇒ Object
Returns the value of attribute end_date.
88 89 90 |
# File 'lib/stocktracker/yahoofinance.rb', line 88 def end_date @end_date end |
#results ⇒ Object
Returns the value of attribute results.
88 89 90 |
# File 'lib/stocktracker/yahoofinance.rb', line 88 def results @results end |
#start_date ⇒ Object
Returns the value of attribute start_date.
88 89 90 |
# File 'lib/stocktracker/yahoofinance.rb', line 88 def start_date @start_date end |
#symbol ⇒ Object
Returns the value of attribute symbol.
88 89 90 |
# File 'lib/stocktracker/yahoofinance.rb', line 88 def symbol @symbol end |
Instance Method Details
#get_past_quote ⇒ Object
107 108 109 110 111 |
# File 'lib/stocktracker/yahoofinance.rb', line 107 def get_past_quote past_map rescue nil end |
#past_map ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/stocktracker/yahoofinance.rb', line 135 def past_map map = {} values = past_values PAST_FORMAT.each_with_index do |v,i| if v.is_a?(Array) map[v[0]] = values[i].send(v[1]) else map[v] = values[i] end end map end |
#past_values ⇒ Object
131 132 133 |
# File 'lib/stocktracker/yahoofinance.rb', line 131 def past_values CSV.parse(yahoo_past_quote)[1] end |
#yahoo_past_quote ⇒ Object
113 114 115 |
# File 'lib/stocktracker/yahoofinance.rb', line 113 def yahoo_past_quote open(yahoo_past_url).read end |
#yahoo_past_url ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/stocktracker/yahoofinance.rb', line 117 def yahoo_past_url URI.encode( "http://itable.finance.yahoo.com/table.csv?"+ "s=#{symbol}&g=d&"+ "a=#{start_date.month-1}&"+ "b=#{start_date.mday}&"+ "c=#{start_date.year}&"+ "d=#{end_date.month-1}&"+ "e=#{end_date.mday}&"+ "f=#{end_date.year}" ) end |