Class: AhlScraper::Season

Inherits:
Resource show all
Defined in:
lib/ahl_scraper/resources/season.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Resource

#[], #each, #inspect, #keys, #to_json, #values

Constructor Details

#initialize(raw_data, opts = {}) ⇒ Season

Returns a new instance of Season.



7
8
9
10
11
12
13
# File 'lib/ahl_scraper/resources/season.rb', line 7

def initialize(raw_data, opts = {})
  super(raw_data, opts)
  @id = raw_data[:id].to_i
  @name = raw_data[:name]
  @season_type = set_season_type
  @division_data = %i[regular playoffs].include?(season_type) ? DivisionDataFetcher.new(@id).call : []
end

Instance Attribute Details

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/ahl_scraper/resources/season.rb', line 5

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/ahl_scraper/resources/season.rb', line 5

def name
  @name
end

#season_typeObject (readonly)

Returns the value of attribute season_type.



5
6
7
# File 'lib/ahl_scraper/resources/season.rb', line 5

def season_type
  @season_type
end

Instance Method Details

#abbreviationObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ahl_scraper/resources/season.rb', line 15

def abbreviation
  @abbreviation ||=
    case season_type
    when :regular
      "#{start_year.to_s[-2..]}-#{end_year.to_s[-2..]}"
    when :playoffs
      "#{start_year.to_s[-2..]}PO"
    when :all_star_game
      "#{start_year.to_s[-2..]}ASG"
    when :exhibition
      "#{start_year.to_s[-2..]}-#{end_year.to_s[-2..]}EX"
    when :preseason
      "#{start_year.to_s[-2..]}PS"
    end
end

#divisionsObject



59
60
61
# File 'lib/ahl_scraper/resources/season.rb', line 59

def divisions
  @divisions ||= @division_data.map { |d| d.dig(:headers, :name, :properties, :title) }
end

#end_dateObject



45
46
47
# File 'lib/ahl_scraper/resources/season.rb', line 45

def end_date
  @end_date ||= set_end_date
end

#end_yearObject



49
50
51
52
53
54
55
56
57
# File 'lib/ahl_scraper/resources/season.rb', line 49

def end_year
  @end_year ||=
    case season_type
    when :regular, :exhibition
      start_year + 1
    when :playoffs, :all_star_game, :preseason
      start_year
    end
end

#start_dateObject



41
42
43
# File 'lib/ahl_scraper/resources/season.rb', line 41

def start_date
  @start_date ||= set_start_date
end

#start_yearObject



31
32
33
34
35
36
37
38
39
# File 'lib/ahl_scraper/resources/season.rb', line 31

def start_year
  @start_year ||=
    case season_type
    when :regular, :exhibition
      name[/(.*?)-/].to_i
    when :playoffs, :all_star_game, :preseason
      name[/(.*?) /].to_i
    end
end

#teamsObject



63
64
65
# File 'lib/ahl_scraper/resources/season.rb', line 63

def teams
  @teams ||= %i[regular playoffs].include?(season_type) ? Seasons::TeamsService.new(@division_data).call : []
end