class PGATourReader::PGA_Season

Attributes

tournaments[RW]
year[RW]

Public Class Methods

all() click to toggle source
# File lib/PGA_season.rb, line 13
def self.all
  @@all
end
get_season_by_year(year) click to toggle source
# File lib/PGA_season.rb, line 27
def self.get_season_by_year(year)
  season = self.all.detect{|season| season.year == year}
  season ? season : PGATourReader::PGA_Tour_Scraper.new(year).season
end
get_tournament(date, year = Time.now.strftime("%Y")) click to toggle source
# File lib/PGA_season.rb, line 47
def self.get_tournament(date, year = Time.now.strftime("%Y"))
  dates = date.split("/")
  puts ""
  puts "your requested date is: #{dates[0]}, #{dates[1]}, #{year}"
  puts ""
  if Date.valid_date?(year.to_i, dates[0].to_i, dates[1].to_i)
    tournament_date = Date.new(year.to_i, dates[0].to_i, dates[1].to_i)
    got_tournament = self.get_tournaments_by_month(dates[0]).detect do |tournament|
      (tournament_date <=> tournament.start_date) > -1 && (tournament_date <=> tournament.end_date) < 1
    end
  else
    puts "that date is invalid, make sure to use the format of mm/dd"
  end
end
get_tournaments_by_month(month_number, year = Time.now.strftime("%Y")) click to toggle source
# File lib/PGA_season.rb, line 32
def self.get_tournaments_by_month(month_number, year = Time.now.strftime("%Y"))
  season = self.get_season_by_year(year)
  if season
    season.tournaments.select {|tournament| tournament.start_date.month == month_number.to_i || tournament.end_date.month == month_number.to_i}
  else
    puts ""
    puts "------------------------------------------------------------"
    puts "I don't have the #{year} season on file let me load the data"
    puts "------------------------------------------------------------"
    puts ""
    PGATourReader::PGA_Tour_Scraper.new(year)
    self.get_tournaments_by_month(month_number, year)
  end
end
new(year, tournaments = []) click to toggle source
# File lib/PGA_season.rb, line 7
def initialize(year, tournaments = [])
  @year = year
  @tournaments = tournaments
  save
end

Public Instance Methods

list_all_for_season() click to toggle source
# File lib/PGA_season.rb, line 21
def list_all_for_season()
  @tournaments.each do |tournament|
    tournament.print_date_name
  end
end
save() click to toggle source
# File lib/PGA_season.rb, line 17
def save
  self.class.all << self
end