Class: TableScraper
- Inherits:
-
Object
- Object
- TableScraper
- Defined in:
- lib/table_scraper.rb
Instance Attribute Summary collapse
-
#teams ⇒ Object
Returns the value of attribute teams.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #build_teams ⇒ Object
- #call ⇒ Object
-
#initialize ⇒ TableScraper
constructor
A new instance of TableScraper.
Constructor Details
#initialize ⇒ TableScraper
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
#teams ⇒ Object
Returns the value of attribute teams.
3 4 5 |
# File 'lib/table_scraper.rb', line 3 def teams @teams end |
#url ⇒ Object
Returns the value of attribute url.
3 4 5 |
# File 'lib/table_scraper.rb', line 3 def url @url end |
Instance Method Details
#build_teams ⇒ Object
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 |
#call ⇒ Object
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 |