class SP500Scraper
Public Instance Methods
scrape()
click to toggle source
# File lib/stock_index/scrapers/SP500_scraper.rb, line 3 def scrape doc = Nokogiri::HTML(open(StockIndex::INDICES['^GSPC'][:url])) parse_rows doc.css('table.wikitable.sortable')[0].css('tr') end
Private Instance Methods
market(tr)
click to toggle source
# File lib/stock_index/scrapers/SP500_scraper.rb, line 16 def market(tr) market_td = td(tr, 0) market_link = market_td ? market_td.css('a').first.attributes['href'].value : nil StockIndex::Market.new(parse_market_link(market_link)).to_iso10383 end
parse_market_link(market_link)
click to toggle source
# File lib/stock_index/scrapers/SP500_scraper.rb, line 26 def parse_market_link(market_link) if market_link uri = URI(market_link) uri.host else nil end end
symbol(tr)
click to toggle source
# File lib/stock_index/scrapers/SP500_scraper.rb, line 10 def symbol(tr) symbol_td = td(tr, 0) s = symbol_td ? symbol_td.css('a').first.text : nil SymbolParser.new(s).symbol_to_bsym end
wikipedia_link(tr)
click to toggle source
# File lib/stock_index/scrapers/SP500_scraper.rb, line 22 def wikipedia_link(tr) wikipedia_position(tr, 1) end