Class: CanadianMergers::Scrape
- Inherits:
-
Object
- Object
- CanadianMergers::Scrape
- Defined in:
- lib/canadian_mergers/scrape.rb
Overview
Scraper class
Instance Attribute Summary collapse
-
#month ⇒ Object
Returns the value of attribute month.
-
#year ⇒ Object
Returns the value of attribute year.
Instance Method Summary collapse
- #get_page ⇒ Object
-
#initialize(year, month) ⇒ Scrape
constructor
A new instance of Scrape.
- #table_data ⇒ Object
Constructor Details
#initialize(year, month) ⇒ Scrape
Returns a new instance of Scrape.
5 6 7 8 |
# File 'lib/canadian_mergers/scrape.rb', line 5 def initialize(year, month) @year = year @month = month end |
Instance Attribute Details
#month ⇒ Object
Returns the value of attribute month.
3 4 5 |
# File 'lib/canadian_mergers/scrape.rb', line 3 def month @month end |
#year ⇒ Object
Returns the value of attribute year.
3 4 5 |
# File 'lib/canadian_mergers/scrape.rb', line 3 def year @year end |
Instance Method Details
#get_page ⇒ Object
10 11 12 |
# File 'lib/canadian_mergers/scrape.rb', line 10 def get_page Nokogiri::HTML(open('http://www.competitionbureau.gc.ca/eic/site/cb-bc.nsf/eng/02435.html')) end |
#table_data ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/canadian_mergers/scrape.rb', line 14 def table_data get_page.css("details#details-panel#{@year}-#{@month}").each do |table| table.css('tbody tr').each do |tag| data = tag.css('td').collect(&:text) CanadianMergers::Merger.create(data[0], data[1], data[2]) end end end |