Class: AhlScraper::Games::Goal

Inherits:
Resource
  • Object
show all
Defined in:
lib/ahl_scraper/resources/games/goal.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

#assist_numbersObject



56
57
58
# File 'lib/ahl_scraper/resources/games/goal.rb', line 56

def assist_numbers
  @assist_numbers ||= @raw_data[:assistNumbers]
end

#assistsObject



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

def assists
  @assists ||= @raw_data[:assists].map do |assist|
    {
      id: assist[:id],
      first_name: assist[:firstName],
      last_name: assist[:lastName],
      number: assist[:jerseyNumber],
      position: assist[:position],
    }
  end
end

#descriptionObject



117
118
119
120
121
122
123
124
125
126
# File 'lib/ahl_scraper/resources/games/goal.rb', line 117

def description
  @description ||=
    if assists.nil? || assists.empty?
      goalscorer_name
    elsif assists.length == 1
      "#{goalscorer_name} (#{a1_name})"
    else
      "#{goalscorer_name} (#{a1_name}, #{a2_name})"
    end
end

#empty_net?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ahl_scraper/resources/games/goal.rb', line 72

def empty_net?
  @empty_net ||= @raw_data[:properties][:isEmptyNet] == "1"
end

#extra_skater?Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/ahl_scraper/resources/games/goal.rb', line 76

def extra_skater?
  @extra_skater ||= set_extra_skater
end

#game_time_elapsedObject



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

def game_time_elapsed
  @game_time_elapsed ||= period_time.to_elapsed
end

#game_winner?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/ahl_scraper/resources/games/goal.rb', line 88

def game_winner?
  @game_winner ||= @raw_data[:properties][:isGameWinningGoal] == "1"
end

#idObject



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

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

#insurance_goal?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/ahl_scraper/resources/games/goal.rb', line 84

def insurance_goal?
  @insurance_goal ||= @raw_data[:properties][:isInsuranceGoal] == "1"
end

#minus_playersObject



96
97
98
# File 'lib/ahl_scraper/resources/games/goal.rb', line 96

def minus_players
  @minus_players ||= @raw_data[:minus_players].map { |player| OnIceSkater.new(player, { scoring_team: false, goal_id: id }) }
end

#numberObject



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

def number
  @number ||= @opts[:number]
end

#penalty_shot?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/ahl_scraper/resources/games/goal.rb', line 80

def penalty_shot?
  @penalty_shot ||= @raw_data[:properties][:isPenaltyShot] == "1"
end

#periodObject



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

def period
  @period ||= @raw_data[:period][:id].to_i
end

#period_time_in_secondsObject



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

def period_time_in_seconds
  @period_time_in_seconds ||= period_time.to_sec
end

#plus_playersObject



92
93
94
# File 'lib/ahl_scraper/resources/games/goal.rb', line 92

def plus_players
  @plus_players ||= @raw_data[:plus_players].map { |player| OnIceSkater.new(player, { scoring_team: true, goal_id: id }) }
end

#power_play?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ahl_scraper/resources/games/goal.rb', line 64

def power_play?
  @power_play ||= @raw_data[:properties][:isPowerPlay] == "1"
end

#scored_byObject



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

def scored_by
  @scored_by ||= {
    id: @raw_data[:scoredBy][:id],
    first_name: @raw_data[:scoredBy][:firstName],
    last_name: @raw_data[:scoredBy][:lastName],
    number: @raw_data[:scoredBy][:jerseyNumber],
    position: @raw_data[:scoredBy][:position],
  }
end

#scorer_goal_numberObject



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

def scorer_goal_number
  @scorer_goal_number ||= @raw_data[:scorerGoalNumber]
end

#scoring_teamObject



60
61
62
# File 'lib/ahl_scraper/resources/games/goal.rb', line 60

def scoring_team
  @scoring_team ||= @raw_data[:team]
end

#short_handed?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/ahl_scraper/resources/games/goal.rb', line 68

def short_handed?
  @short_handed ||= @raw_data[:properties][:isShortHanded] == "1"
end

#situationObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/ahl_scraper/resources/games/goal.rb', line 100

def situation
  @situation ||=
    if @raw_data[:properties][:isPowerPlay] == "1"
      "PP"
    elsif @raw_data[:properties][:isShortHanded] == "1"
      "SH"
    elsif @raw_data[:properties][:isEmptyNet] == "1"
      "EN"
    elsif extra_skater? == true
      "EX"
    elsif @raw_data[:properties][:isPenaltyShot] == "1"
      "PS"
    else
      "EV"
    end
end

#special_teams?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/ahl_scraper/resources/games/goal.rb', line 128

def special_teams?
  @special_teams ||= short_handed? || power_play?
end

#timeObject



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

def time
  @time ||= @raw_data[:time]
end