Class: AhlScraper::Season
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
#id ⇒ Object
Returns the value of attribute id.
5
6
7
|
# File 'lib/ahl_scraper/resources/season.rb', line 5
def id
@id
end
|
#name ⇒ Object
Returns the value of attribute name.
5
6
7
|
# File 'lib/ahl_scraper/resources/season.rb', line 5
def name
@name
end
|
#season_type ⇒ Object
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
#abbreviation ⇒ Object
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
|
#divisions ⇒ Object
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_date ⇒ Object
45
46
47
|
# File 'lib/ahl_scraper/resources/season.rb', line 45
def end_date
@end_date ||= set_end_date
end
|
#end_year ⇒ Object
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_date ⇒ Object
41
42
43
|
# File 'lib/ahl_scraper/resources/season.rb', line 41
def start_date
@start_date ||= set_start_date
end
|
#start_year ⇒ Object
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
|
#teams ⇒ Object
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
|