Class: LedgerWeb::YahooPriceLookup
- Inherits:
-
Object
- Object
- LedgerWeb::YahooPriceLookup
- Defined in:
- lib/ledger_web/price_lookup.rb
Instance Method Summary collapse
-
#initialize(symbol, min_date, max_date) ⇒ YahooPriceLookup
constructor
A new instance of YahooPriceLookup.
- #lookup ⇒ Object
Constructor Details
#initialize(symbol, min_date, max_date) ⇒ YahooPriceLookup
Returns a new instance of YahooPriceLookup.
7 8 9 10 11 |
# File 'lib/ledger_web/price_lookup.rb', line 7 def initialize(symbol, min_date, max_date) @symbol = symbol @min_date = min_date @max_date = max_date end |
Instance Method Details
#lookup ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ledger_web/price_lookup.rb', line 13 def lookup params = { 'a' => @min_date.month - 1, 'b' => @min_date.day, 'c' => @min_date.year, 'd' => @max_date.month - 1, 'e' => @max_date.day, 'f' => @max_date.year, 's' => @symbol, 'ignore' => '.csv', } query = params.map { |k,v| "#{k}=#{v}" }.join("&") uri = URI.parse("http://ichart.finance.yahoo.com/table.csv?#{query}") response = Net::HTTP.get_response(uri) if response.code != '200' return [] end rows = [] CSV.parse(response.body, :headers => true) do |row| rows << [Date.parse(row["Date"]), row["Close"].to_f] end rows end |