Class: StockIndex::BaseScraper
- Inherits:
-
Object
- Object
- StockIndex::BaseScraper
show all
- Defined in:
- lib/stock_index/scrapers/base_scraper.rb
Instance Method Summary
collapse
Instance Method Details
#build_wikipedia_link(wikipedia_path) ⇒ Object
29
30
31
|
# File 'lib/stock_index/scrapers/base_scraper.rb', line 29
def build_wikipedia_link(wikipedia_path)
URI::Generic.new('https', nil, 'en.wikipedia.org', nil, nil, wikipedia_path, nil, nil, nil).to_s rescue nil
end
|
#parse_rows(rows) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/stock_index/scrapers/base_scraper.rb', line 7
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_link(tr))
array << component.attributes
end
array
end
end
|
#td(tr, position) ⇒ Object
19
20
21
|
# File 'lib/stock_index/scrapers/base_scraper.rb', line 19
def td(tr, position)
tr.css('td')[position]
end
|
#wikipedia_position(tr, position) ⇒ Object
23
24
25
26
27
|
# File 'lib/stock_index/scrapers/base_scraper.rb', line 23
def wikipedia_position(tr, position)
wikipedia_td = tr.css('td')[position]
wikipedia_path = wikipedia_td ? wikipedia_td.css('a').first.attributes['href'].value : nil
build_wikipedia_link(wikipedia_path)
end
|