Class: Fsxtrader::QuoteParser

Inherits:
Object
  • Object
show all
Defined in:
lib/fsxtrader/quote_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(symbols) ⇒ QuoteParser

Returns a new instance of QuoteParser.



4
5
6
7
8
# File 'lib/fsxtrader/quote_parser.rb', line 4

def initialize(symbols)
  @url = "http://finance.yahoo.com/d/quotes.csv?s=#{symbols.join('+').upcase}&f=sl1"
  @raw_csv = open(@url)
  parse
end

Instance Attribute Details

#quotesObject

Returns the value of attribute quotes.



3
4
5
# File 'lib/fsxtrader/quote_parser.rb', line 3

def quotes
  @quotes
end

Instance Method Details

#parseObject



10
11
12
13
14
15
16
17
18
# File 'lib/fsxtrader/quote_parser.rb', line 10

def parse
  @quotes = Hash.new
  @raw_csv.each_line do |line|
    #puts "Parsed Yahoo Stock Quote Line: #{line}"
    line.gsub!('"', '')
    symbol, price = *line.split(',')
    @quotes[symbol] = price.to_f
  end
end