class PGATourReader::PGA_Tour_Parser

Public Class Methods

attribute_parser(tournament_info) click to toggle source

retuns hash of name, course, location (always) and purse, url if available

# File lib/PGA_Tour_parser.rb, line 22
def self.attribute_parser(tournament_info)
  attribute_text = tournament_info.children[4].text.split(/\s{2,}/)
  attribute_text.shift
  attributes = {
    :name => tournament_info.children[1].children[0].text,
    :url => self.url_parser(tournament_info),
    :course => attribute_text[0].split(",")[0],
    :location => "#{attribute_text[1]}#{attribute_text[2]}"[0..-2]
  }
  attributes[:purse] = "#{attribute_text[3].split(":")[1].strip}" if attribute_text.length == 4
  attributes
end
date_parser(month, days) click to toggle source

returns array of 2 dates, start at [0] end at [1]

# File lib/PGA_Tour_parser.rb, line 4
def self.date_parser(month, days)
  if /\d/ =~ month #when tourny weekend spans end of month
    start_date = Date.parse("#{month} #{@year}")
    end_date = Date.parse("#{days} #{@year}")
  else #when tourny weekend starts and ends same month
    days = days.split(" - ")
    start_date = Date.parse("#{month} #{days[0]} #{@year}")
    end_date = Date.parse("#{month} #{days[1]} #{@year}")
  end
  [self.set_year(start_date), self.set_year(end_date)]
end
set_year(date) click to toggle source

corrects the year for tournaments at the beginning of season

# File lib/PGA_Tour_parser.rb, line 17
def self.set_year(date)
  date.month.between?(10,12) ? date << 12 : date #new seasons start in oct (month 10)
end
url_parser(tournament_info) click to toggle source

returns standardized url (if there is one) into https:// format

# File lib/PGA_Tour_parser.rb, line 36
def self.url_parser(tournament_info)
  url = tournament_info.children[1].attributes["href"]
  if url
    url.value.start_with?("/") ? url = "https://www.pgatour.com#{url.value}" : url = url.value
  end
end