Class: TableScraper

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTableScraper

Returns a new instance of TableScraper.



5
6
7
# File 'lib/table_scraper.rb', line 5

def initialize
  @url = "http://www.theguardian.com/football/" + LeagueReference::league_full_name + "/table"
end

Instance Attribute Details

#teamsObject

Returns the value of attribute teams.



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

def teams
  @teams
end

#urlObject

Returns the value of attribute url.



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

def url
  @url
end

Instance Method Details

#build_teamsObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/table_scraper.rb', line 15

def build_teams
  teams.length.times do |i|
    source = teams[i].children
    Team.new({
      :name => source[2].children[-1].children.text,
      :played => source[4].children.text,
      :points => source[-2].text,
      :position => source[0].children.text
    })
  end
end

#callObject



9
10
11
12
13
# File 'lib/table_scraper.rb', line 9

def call
  site = Nokogiri::HTML(open(self.url))
  self.teams = site.css('.table-football-body tr')[3..-1]
  build_teams
end