Sha256: e2468ef91c154d476380eeb81dd19cfc358d697cbca59c7d96d98d13af312d63

Contents?: true

Size: 759 Bytes

Versions: 9

Compression:

Stored size: 759 Bytes

Contents

class SP500Scraper < StockIndex::BaseScraper

  def scrape
    doc = Nokogiri::HTML(open(StockIndex::INDICES['^GSPC'][:url]))
    parse_rows doc.css('table.wikitable.sortable')[0].css('tr')
  end

  private

  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

  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

  def wikipedia_link(tr)
    wikipedia_position(tr, 1)
  end

  def parse_market_link(market_link)
    if market_link
      uri = URI(market_link)
      uri.host
    else
      nil
    end
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
stock_index-0.8.8 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.7 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.6 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.5 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.4 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.3 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.2 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.1 lib/stock_index/scrapers/SP500_scraper.rb
stock_index-0.8.0 lib/stock_index/scrapers/SP500_scraper.rb