Class: CanadianMergers::Scrape

Inherits:
Object
  • Object
show all
Defined in:
lib/canadian_mergers/scrape.rb

Overview

Scraper class

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#monthObject

Returns the value of attribute month.



3
4
5
# File 'lib/canadian_mergers/scrape.rb', line 3

def month
  @month
end

#yearObject

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_pageObject



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_dataObject



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