Class: AhlScraper::Games::OnIceStatlinesService
- Inherits:
-
Object
- Object
- AhlScraper::Games::OnIceStatlinesService
- Defined in:
- lib/ahl_scraper/services/games/on_ice_statlines_service.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(goal_data, team_id, skater_ids) ⇒ OnIceStatlinesService
constructor
A new instance of OnIceStatlinesService.
Constructor Details
#initialize(goal_data, team_id, skater_ids) ⇒ OnIceStatlinesService
Returns a new instance of OnIceStatlinesService.
6 7 8 9 10 |
# File 'lib/ahl_scraper/services/games/on_ice_statlines_service.rb', line 6 def initialize(goal_data, team_id, skater_ids) @goal_data = goal_data @team_id = team_id @skater_ids = skater_ids end |
Instance Method Details
#call ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ahl_scraper/services/games/on_ice_statlines_service.rb', line 12 def call @goal_data.each do |goal| next if goal[:properties][:isPenaltyShot] == "1" goal_status = goal[:team][:id] == @team_id ? "gf" : "ga" on_scoring_team = goal[:team][:id] == @team_id plus_player_ids = goal[:plus_players].map { |pl| pl[:id].to_s } minus_player_ids = goal[:minus_players].map { |pl| pl[:id].to_s } skater_ids = on_scoring_team ? plus_player_ids : minus_player_ids opposing_skater_ids = on_scoring_team ? minus_player_ids : plus_player_ids goal_situation = find_goal_situation(goal, on_scoring_team) goal_player_counts = find_goal_player_counts(skater_ids, opposing_skater_ids, on_scoring_team) skater_ids.map(&:to_s).each do |skater_id| on_ice_statlines[skater_id] ||= blank_statline on_ice_statlines[skater_id]["#{goal_status}_as".to_sym] += 1 on_ice_statlines[skater_id]["#{goal_status}_#{goal_situation}".to_sym] += 1 next unless opposing_skater_ids.length >= 3 && skater_ids.length >= 3 && opposing_skater_ids.length <= 6 && skater_ids.length <= 6 on_ice_statlines[skater_id]["#{goal_status}_#{goal_player_counts}".to_sym] += 1 end end on_ice_statlines end |