class PGATourReader::PGA_Tour_Scraper

Attributes

path[RW]
season[RW]
year[RW]

Public Class Methods

new(year = Time.now.strftime("%Y"), path = "https://www.pgatour.com/tournaments/schedule.html") click to toggle source
# File lib/PGA_Tour_scraper.rb, line 5
def initialize(year = Time.now.strftime("%Y"), path = "https://www.pgatour.com/tournaments/schedule.html")
  @path = path
  @year = year
  @season = PGATourReader::PGA_Season.new(@year)
  scrape_tour_page
end

Public Instance Methods

attribute_scraper(page) click to toggle source

scrapes name location course url and purse data and returns them in a hash

# File lib/PGA_Tour_scraper.rb, line 30
def attribute_scraper(page)
  page.css(".tournament-text").map {|tournament_info| PGATourReader::PGA_Tour_Parser.attribute_parser(tournament_info)}
end
date_scraper(page) click to toggle source

scrapes all dates for a given season and returns an array of created Tournaments

# File lib/PGA_Tour_scraper.rb, line 22
def date_scraper(page)
  page.css('.num-date').each do |date_info|
    dates = PGATourReader::PGA_Tour_Parser.date_parser(date_info.children[1].children.text, date_info.children[3].children.text.strip)
    @season.tournaments << PGATourReader::PGA_Tournament.new(dates[0], dates[1], @season)
  end
end
scrape_tour_page() click to toggle source

scrapes parses and zips all tournaments and their attributes for a season

# File lib/PGA_Tour_scraper.rb, line 13
def scrape_tour_page
  page = Nokogiri::HTML(open("#{@path}"))
  date_scraper(page) #instantiates all tournaments from this season by dates
  tournament_attributes = attribute_scraper(page)
  #zips together tournament attributes with tournament objects
  @season.tournaments.each_with_index {|tournament, index| tournament.add_attributes(tournament_attributes[index])}
end