Class: AtpRankings::Scraper

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

Instance Method Summary collapse

Instance Method Details

#create_athletesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/atp_rankings/scraper.rb', line 10

def create_athletes
  i = 1
  while i < 26 do
    scrape_athletes_index.each do |a|
      athlete = AtpRankings::Athlete.new
      athlete.rank = a.search("tr[#{i}] .rank-cell").text.strip
      athlete.name = a.search("tr[#{i}] .player-cell").text.strip
      athlete.age = a.search("tr[#{i}] .age-cell").text.strip
      athlete.points = a.search("tr[#{i}] .points-cell").text.strip
      athlete.tourn_played = a.search("tr[#{i}] .tourn-cell").text.strip
      athlete.url = "http://www.atpworldtour.com" + a.search("tr[#{i}] .player-cell a").attr("href").text
      i += 1
    end
  end
end

#get_pageObject



2
3
4
# File 'lib/atp_rankings/scraper.rb', line 2

def get_page
  Nokogiri::HTML(open("http://www.atpworldtour.com/en/rankings/singles-race-to-london"))
end

#scrape_athletes_indexObject



6
7
8
# File 'lib/atp_rankings/scraper.rb', line 6

def scrape_athletes_index
  self.get_page.search("#singlesRanking")
end