Class: AhlScraper::Games::Team

Inherits:
Resource
  • Object
show all
Defined in:
lib/ahl_scraper/resources/games/team.rb

Instance Method Summary collapse

Methods inherited from Resource

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

Constructor Details

This class inherits a constructor from AhlScraper::Resource

Instance Method Details

#abbreviationObject



22
23
24
# File 'lib/ahl_scraper/resources/games/team.rb', line 22

def abbreviation
  @abbreviation ||= @raw_data[:info][:abbreviation]
end

#cityObject



14
15
16
# File 'lib/ahl_scraper/resources/games/team.rb', line 14

def city
  @city ||= @raw_data[:info][:city]
end

#full_nameObject



10
11
12
# File 'lib/ahl_scraper/resources/games/team.rb', line 10

def full_name
  @full_name ||= @raw_data[:info][:name]
end

#goal_statsObject



56
57
58
59
60
61
62
63
64
# File 'lib/ahl_scraper/resources/games/team.rb', line 56

def goal_stats
  @goal_stats ||= {
    goals: @opts[:goal_totals].map { |period| period[home_team? ? :home : :away] }.reduce(:+),
    p1_goals: @opts[:goal_totals].dig(0, home_team? ? :home : :away),
    p2_goals: @opts[:goal_totals].dig(1, home_team? ? :home : :away),
    p3_goals: @opts[:goal_totals].dig(2, home_team? ? :home : :away),
    ot_goals: @opts[:goal_totals][3..]&.map { |ot| ot[home_team? ? :home : :away].to_i },
  }
end

#home_team?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ahl_scraper/resources/games/team.rb', line 30

def home_team?
  @home_team ||= @opts[:home_team]
end

#idObject



6
7
8
# File 'lib/ahl_scraper/resources/games/team.rb', line 6

def id
  @id ||= @raw_data[:info][:id]
end

#logo_urlObject



26
27
28
# File 'lib/ahl_scraper/resources/games/team.rb', line 26

def logo_url
  @logo_url ||= @raw_data[:info][:logo]
end

#nameObject



18
19
20
# File 'lib/ahl_scraper/resources/games/team.rb', line 18

def name
  @name ||= @raw_data[:info][:nickname] == @raw_data[:info][:city] ? parse_nickname : @raw_data[:info][:nickname]
end

#on_ice_statsObject



66
67
68
# File 'lib/ahl_scraper/resources/games/team.rb', line 66

def on_ice_stats
  @on_ice_stats ||= TeamOnIceGoalsService.new(id, @opts[:goals]).call
end

#shot_statsObject



46
47
48
49
50
51
52
53
54
# File 'lib/ahl_scraper/resources/games/team.rb', line 46

def shot_stats
  @shot_stats ||= {
    sog: @opts[:shots].map { |period| period[home_team? ? :home : :away] }.reduce(:+),
    p1_sog: @opts[:shots].dig(0, home_team? ? :home : :away),
    p2_sog: @opts[:shots].dig(1, home_team? ? :home : :away),
    p3_sog: @opts[:shots].dig(2, home_team? ? :home : :away),
    ot_sog: @opts[:shots][3..]&.map { |ot| ot[home_team? ? :home : :away].to_i },
  }
end

#statsObject



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ahl_scraper/resources/games/team.rb', line 34

def stats
  @stats ||= {
    score: score,
    hits: @raw_data[:stats][:hits],
    power_play_goals: @raw_data[:stats][:powerPlayGoals],
    power_play_opportunities: @raw_data[:stats][:powerPlayOpportunities],
    goals: @raw_data[:stats][:goalCount],
    penalty_minute_count: @raw_data[:stats][:penaltyMinuteCount],
    infraction_count: @raw_data[:stats][:infractionCount],
  }
end

#time_splitsObject



70
71
72
# File 'lib/ahl_scraper/resources/games/team.rb', line 70

def time_splits
  @time_splits ||= TimeSplitsService.new(@opts[:goals], id, @opts[:current_state], @opts[:game_properties]).call
end