class TickerFetcher::Retriever
Attributes
exchanges[R]
Public Class Methods
new()
click to toggle source
Passing an exchange name will retrieve only that exchange. Default is to retrieve all.
# File lib/ticker_fetcher/retriever.rb, line 10 def initialize @exchanges = {} end
Public Instance Methods
[](exchange)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 27 def [](exchange) exchanges[exchange] end
parse_exchange(exchange, url)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 22 def parse_exchange(exchange, url) data = open(url) parse_csv(data) end
run(exchange=:all)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 14 def run(exchange=:all) if exchange == :all EXCHANGE_URLS.each { |exchange, url| @exchanges[exchange] = parse_exchange(exchange, url) } else @exchanges[exchange] = parse_exchange(exchange, EXCHANGE_URLS[exchange]) end end
Private Instance Methods
industry(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 62 def industry(row) row['Industry'] end
last_sale(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 50 def last_sale(row) row['LastSale'] end
market_cap(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 54 def market_cap(row) row['MarketCap'] end
name(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 39 def name(row) row['Name'] end
parse_csv(data)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 33 def parse_csv(data) CSV.parse(data, headers: true).inject([]) do |stocks, row| stocks << TickerFetcher::Stock.new(row) end end
sector(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 58 def sector(row) row['Sector'] end
ticker(row)
click to toggle source
# File lib/ticker_fetcher/retriever.rb, line 43 def ticker(row) ticker = row['Symbol'].strip.gsub('"', '') unless(ticker.nil? || ticker.empty?) ticker = ticker =~ /\W/ ? ticker.gsub('/', '.').gsub('^', '-') : ticker end end