Sha256: 24f0bd3241b43b2672c85abefdd38b1da8291f9c80b99e0d669c7bf62d32babc

Contents?: true

Size: 751 Bytes

Versions: 1

Compression:

Stored size: 751 Bytes

Contents

class StockIndex

  class BaseScraper

    require 'nokogiri'

    def parse_rows(rows)
      rows.inject([]) do |array, tr|
        symbol = symbol(tr)
        market = market(tr)
        if symbol && market
          component = StockIndex::Component.new(symbol, market, wikipedia(tr))
          array << component.attributes if component.valid?
        end
        array
      end
    end

    def td(tr, position)
      tr.css('td')[position]
    end

    def wikipedia_position(tr, position)
      wikipedia_td = tr.css('td')[position]
      wikipedia_path = wikipedia_td ? wikipedia_td.css('a').first.attributes['href'].value : nil
      URI::HTTP.build({:host => 'en.wikipedia.org', :path => wikipedia_path}).to_s rescue nil
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
stock_index-0.5.1 lib/stock_index/scrapers/base_scraper.rb