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 = "https://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 26 27 28 29 30 |
# File 'lib/table_scraper.rb', line 15 def build_teams teams.length.times do |i| source = teams[i].children.text team_data = source.split("\n").select { |s| s != "" } #["1", "Spurs", "2", "2", "0", "0", "5", "0", "5", "6"] #Pos Team P W D L F A GD Pts Team.new({ :position => team_data[0], :name => team_data[1], :played => team_data[2], :points => team_data[9] }) end end |
#call ⇒ Object
9 10 11 12 13 |
# File 'lib/table_scraper.rb', line 9 def call site = Nokogiri::HTML(open(@url)) self.teams = site.css('.table--league-table tbody tr') build_teams end |