ahl_scraper 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +12 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +85 -0
  5. data/.ruby-version +1 -0
  6. data/.solargraph.yml +15 -0
  7. data/.travis.yml +6 -0
  8. data/.vscode/settings.json +11 -0
  9. data/CODE_OF_CONDUCT.md +74 -0
  10. data/Gemfile +25 -0
  11. data/Gemfile.lock +114 -0
  12. data/LICENSE.txt +21 -0
  13. data/README.md +235 -0
  14. data/Rakefile +8 -0
  15. data/ahl_scraper.gemspec +27 -0
  16. data/bin/console +16 -0
  17. data/bin/setup +8 -0
  18. data/lib/ahl_scraper.rb +55 -0
  19. data/lib/ahl_scraper/fetchers/division_data_fetcher.rb +19 -0
  20. data/lib/ahl_scraper/fetchers/game_data_fetcher.rb +29 -0
  21. data/lib/ahl_scraper/fetchers/game_event_data_fetcher.rb +19 -0
  22. data/lib/ahl_scraper/fetchers/player_data_fetcher.rb +25 -0
  23. data/lib/ahl_scraper/fetchers/player_games/data_fetcher.rb +30 -0
  24. data/lib/ahl_scraper/fetchers/playoff_bracket_data_fetcher.rb +19 -0
  25. data/lib/ahl_scraper/fetchers/season_data_fetcher.rb +15 -0
  26. data/lib/ahl_scraper/fetchers/season_end_date_fetcher.rb +34 -0
  27. data/lib/ahl_scraper/fetchers/season_game_ids_fetcher.rb +21 -0
  28. data/lib/ahl_scraper/fetchers/season_start_date_fetcher.rb +30 -0
  29. data/lib/ahl_scraper/fetchers/season_type_fetcher.rb +33 -0
  30. data/lib/ahl_scraper/fetchers/team_data_fetcher.rb +19 -0
  31. data/lib/ahl_scraper/fetchers/team_games/data_fetcher.rb +22 -0
  32. data/lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb +67 -0
  33. data/lib/ahl_scraper/fixed_games/1001050.json +2182 -0
  34. data/lib/ahl_scraper/fixed_games/1018774.json +2573 -0
  35. data/lib/ahl_scraper/fixed_games/1020527.json +2483 -0
  36. data/lib/ahl_scraper/games.rb +46 -0
  37. data/lib/ahl_scraper/games/events.rb +8 -0
  38. data/lib/ahl_scraper/helpers/birthdate_helper.rb +27 -0
  39. data/lib/ahl_scraper/helpers/elapsed_time_helper.rb +24 -0
  40. data/lib/ahl_scraper/helpers/ice_time_helper.rb +18 -0
  41. data/lib/ahl_scraper/helpers/parameterize_helper.rb +35 -0
  42. data/lib/ahl_scraper/helpers/period_time_helper.rb +25 -0
  43. data/lib/ahl_scraper/helpers/season_dates_helper.rb +14 -0
  44. data/lib/ahl_scraper/player_games.rb +19 -0
  45. data/lib/ahl_scraper/players.rb +12 -0
  46. data/lib/ahl_scraper/playoff_brackets.rb +17 -0
  47. data/lib/ahl_scraper/resource.rb +38 -0
  48. data/lib/ahl_scraper/resources/game.rb +373 -0
  49. data/lib/ahl_scraper/resources/game_list_item.rb +57 -0
  50. data/lib/ahl_scraper/resources/games/coach.rb +23 -0
  51. data/lib/ahl_scraper/resources/games/events/shot.rb +10 -0
  52. data/lib/ahl_scraper/resources/games/goal.rb +161 -0
  53. data/lib/ahl_scraper/resources/games/goalie.rb +106 -0
  54. data/lib/ahl_scraper/resources/games/info.rb +83 -0
  55. data/lib/ahl_scraper/resources/games/on_ice_skater.rb +35 -0
  56. data/lib/ahl_scraper/resources/games/overtime.rb +48 -0
  57. data/lib/ahl_scraper/resources/games/penalty.rb +101 -0
  58. data/lib/ahl_scraper/resources/games/penalty_shot.rb +82 -0
  59. data/lib/ahl_scraper/resources/games/period.rb +31 -0
  60. data/lib/ahl_scraper/resources/games/referee.rb +23 -0
  61. data/lib/ahl_scraper/resources/games/shootout_attempt.rb +61 -0
  62. data/lib/ahl_scraper/resources/games/skater.rb +94 -0
  63. data/lib/ahl_scraper/resources/games/star.rb +47 -0
  64. data/lib/ahl_scraper/resources/games/team.rb +85 -0
  65. data/lib/ahl_scraper/resources/goalie_game_list_item.rb +69 -0
  66. data/lib/ahl_scraper/resources/player.rb +71 -0
  67. data/lib/ahl_scraper/resources/playoff_bracket.rb +21 -0
  68. data/lib/ahl_scraper/resources/playoff_brackets/game.rb +43 -0
  69. data/lib/ahl_scraper/resources/playoff_brackets/round.rb +31 -0
  70. data/lib/ahl_scraper/resources/playoff_brackets/series.rb +73 -0
  71. data/lib/ahl_scraper/resources/playoff_brackets/team.rb +39 -0
  72. data/lib/ahl_scraper/resources/roster_player.rb +71 -0
  73. data/lib/ahl_scraper/resources/season.rb +93 -0
  74. data/lib/ahl_scraper/resources/season_list_item.rb +30 -0
  75. data/lib/ahl_scraper/resources/seasons/team.rb +77 -0
  76. data/lib/ahl_scraper/resources/skater_game_list_item.rb +65 -0
  77. data/lib/ahl_scraper/resources/team_game_list_item.rb +64 -0
  78. data/lib/ahl_scraper/resources/team_list_item.rb +20 -0
  79. data/lib/ahl_scraper/roster_players.rb +11 -0
  80. data/lib/ahl_scraper/seasons.rb +31 -0
  81. data/lib/ahl_scraper/services/games/create_skaters_service.rb +72 -0
  82. data/lib/ahl_scraper/services/games/on_ice_statlines_service.rb +117 -0
  83. data/lib/ahl_scraper/services/games/penalty_shot_statlines_service.rb +38 -0
  84. data/lib/ahl_scraper/services/games/penalty_shots_service.rb +30 -0
  85. data/lib/ahl_scraper/services/games/penalty_statlines_service.rb +62 -0
  86. data/lib/ahl_scraper/services/games/scoring_statlines_service.rb +115 -0
  87. data/lib/ahl_scraper/services/games/shootout_statlines_service.rb +42 -0
  88. data/lib/ahl_scraper/services/games/team_on_ice_goals_service.rb +152 -0
  89. data/lib/ahl_scraper/services/games/time_splits_service.rb +70 -0
  90. data/lib/ahl_scraper/services/seasons/teams_service.rb +20 -0
  91. data/lib/ahl_scraper/team_games.rb +17 -0
  92. data/lib/ahl_scraper/teams.rb +11 -0
  93. data/lib/ahl_scraper/version.rb +5 -0
  94. metadata +138 -0
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class OnIceSkater < Resource
6
+ def id
7
+ @id ||= @raw_data[:id]
8
+ end
9
+
10
+ def goal_id
11
+ @goal_id ||= @opts[:goal_id]
12
+ end
13
+
14
+ def first_name
15
+ @first_name ||= @raw_data[:firstName]
16
+ end
17
+
18
+ def last_name
19
+ @last_name ||= @raw_data[:lastName]
20
+ end
21
+
22
+ def jersey_number
23
+ @jersey_number ||= @raw_data[:jerseyNumber]
24
+ end
25
+
26
+ def position
27
+ @position ||= @raw_data[:position]
28
+ end
29
+
30
+ def scoring_team?
31
+ @scoring_team ||= @opts[:scoring_team]
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class Overtime < Resource
6
+ def number
7
+ @number ||= @raw_data[:info][:id].to_i - 3
8
+ end
9
+
10
+ def name
11
+ @name ||= "#{@raw_data[:info][:longName]}#{number}"
12
+ end
13
+
14
+ def length
15
+ @length ||= ElapsedTimeHelper.new(length_in_seconds).to_min
16
+ end
17
+
18
+ def length_in_seconds
19
+ @length_in_seconds ||=
20
+ if scoring?
21
+ PeriodTimeHelper.new(@raw_data[:goals][0][:time]).to_sec
22
+ else
23
+ @opts[:regular_season] ? 300 : 1200
24
+ end
25
+ end
26
+
27
+ def scoring?
28
+ @scoring ||= @raw_data[:goals].any?
29
+ end
30
+
31
+ def home_goals
32
+ @home_goals ||= @raw_data[:stats][:homeGoals].to_i
33
+ end
34
+
35
+ def home_sog
36
+ @home_sog ||= @raw_data[:stats][:homeShots].to_i
37
+ end
38
+
39
+ def away_goals
40
+ @away_goals ||= @raw_data[:stats][:visitingGoals].to_i
41
+ end
42
+
43
+ def away_sog
44
+ @away_sog ||= @raw_data[:stats][:visitingShots].to_i
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class Penalty < Resource
6
+ def number
7
+ @number ||= @opts[:number]
8
+ end
9
+
10
+ def period
11
+ @period ||= @raw_data.dig(:period, :id).to_i
12
+ end
13
+
14
+ def time
15
+ @time ||= @raw_data[:time]
16
+ end
17
+
18
+ def period_time_in_seconds
19
+ @period_time_in_seconds ||= period_time.to_sec
20
+ end
21
+
22
+ def game_time_elapsed
23
+ @game_time_elapsed ||= period_time.to_elapsed
24
+ end
25
+
26
+ def taken_by
27
+ @taken_by ||= {
28
+ id: @raw_data.dig(:takenBy, :id)&.positive? ? @raw_data.dig(:takenBy, :id) : nil,
29
+ first_name: @raw_data.dig(:takenBy, :firstName),
30
+ last_name: @raw_data.dig(:takenBy, :lastName),
31
+ jersey_number: @raw_data.dig(:takenBy, :jerseyNumber),
32
+ position: @raw_data.dig(:takenBy, :position),
33
+ birthdate: @raw_data.dig(:takenBy, :birthdate),
34
+ }
35
+ end
36
+
37
+ def served_by
38
+ @served_by ||= {
39
+ id: @raw_data.dig(:servedBy, :id)&.positive? ? @raw_data.dig(:servedBy, :id) : nil,
40
+ first_name: @raw_data.dig(:servedBy, :firstName),
41
+ last_name: @raw_data.dig(:servedBy, :lastName),
42
+ jersey_number: @raw_data.dig(:servedBy, :jerseyNumber),
43
+ position: @raw_data.dig(:servedBy, :position),
44
+ birthdate: @raw_data.dig(:servedBy, :birthdate),
45
+ }
46
+ end
47
+
48
+ def penalized_team
49
+ @penalized_team ||= @raw_data[:againstTeam]
50
+ end
51
+
52
+ def minutes
53
+ @minutes ||= @raw_data[:minutes]
54
+ end
55
+
56
+ def duration
57
+ @duration ||= "#{minutes}:00"
58
+ end
59
+
60
+ def duration_in_seconds
61
+ @duration_in_seconds ||= minutes * 60
62
+ end
63
+
64
+ def description
65
+ @description ||= @raw_data[:description]
66
+ end
67
+
68
+ def rule_number
69
+ @rule_number ||= @raw_data[:rule_number]
70
+ end
71
+
72
+ def power_play?
73
+ @power_play ||= @raw_data[:isPowerPlay]
74
+ end
75
+
76
+ def penalty_type
77
+ @penalty_type ||=
78
+ case @raw_data[:description]
79
+ when /double minor/i
80
+ :double_minor
81
+ when /major/i
82
+ :major
83
+ when /fighting/i
84
+ :fight
85
+ when /game misconduct/i
86
+ :game_misconduct
87
+ when /misconduct/i
88
+ :misconduct
89
+ else
90
+ :minor
91
+ end
92
+ end
93
+
94
+ private
95
+
96
+ def period_time
97
+ @period_time ||= PeriodTimeHelper.new(time, period)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class PenaltyShot < Resource
6
+ def number
7
+ @number ||= @opts[:number]
8
+ end
9
+
10
+ def shooter
11
+ @shooter ||= {
12
+ id: @raw_data[:shooter][:id],
13
+ first_name: @raw_data[:shooter][:firstName],
14
+ last_name: @raw_data[:shooter][:lastName],
15
+ jersey_number: @raw_data[:shooter][:jerseyNumber],
16
+ position: @raw_data[:shooter][:position],
17
+ }
18
+ end
19
+
20
+ def goalie
21
+ @goalie ||= {
22
+ id: @raw_data[:goalie][:id],
23
+ first_name: @raw_data[:goalie][:firstName],
24
+ last_name: @raw_data[:goalie][:lastName],
25
+ jersey_number: @raw_data[:goalie][:jerseyNumber],
26
+ position: @raw_data[:goalie][:position],
27
+ }
28
+ end
29
+
30
+ def shooting_team
31
+ @shooting_team ||= {
32
+ id: @raw_data[:shooter_team][:id],
33
+ full_name: @raw_data[:shooter_team][:name],
34
+ city: @raw_data[:shooter_team][:city],
35
+ name: @raw_data[:shooter_team][:nickname],
36
+ abbreviation: @raw_data[:shooter_team][:abbreviation],
37
+ logo_url: @raw_data[:shooter_team][:logo],
38
+ }
39
+ end
40
+
41
+ def period
42
+ @period ||= @raw_data[:period][:id].to_i
43
+ end
44
+
45
+ def time
46
+ @time ||= @raw_data[:time]
47
+ end
48
+
49
+ def period_time_in_seconds
50
+ @period_time_in_seconds ||= period_time.to_sec
51
+ end
52
+
53
+ def game_time_elapsed
54
+ @game_time_elapsed ||= period_time.to_elapsed
55
+ end
56
+
57
+ def scored?
58
+ @scored ||= @raw_data[:isGoal] == true
59
+ end
60
+
61
+ def scored_in_words
62
+ @scored_in_words ||=
63
+ if scored?
64
+ "Scored"
65
+ else
66
+ "Missed"
67
+ end
68
+ end
69
+
70
+ private
71
+
72
+ def period_time
73
+ @period_time ||= PeriodTimeHelper.new(time, period)
74
+ end
75
+
76
+ def convert_time(game_time)
77
+ time = game_time.split(":")
78
+ time[0].to_i * 60 + time[1].to_i
79
+ end
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class Period < Resource
6
+ def number
7
+ @number ||= @raw_data[:info][:id].to_i
8
+ end
9
+
10
+ def name
11
+ @name ||= @raw_data[:info][:longName]
12
+ end
13
+
14
+ def home_goals
15
+ @home_goals ||= @raw_data[:stats][:homeGoals]
16
+ end
17
+
18
+ def home_sog
19
+ @home_sog ||= @raw_data[:stats][:homeShots]
20
+ end
21
+
22
+ def away_goals
23
+ @away_goals ||= @raw_data[:stats][:visitingGoals]
24
+ end
25
+
26
+ def away_sog
27
+ @away_sog ||= @raw_data[:stats][:visitingShots]
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class Referee < Resource
6
+ def first_name
7
+ @first_name ||= @raw_data[:firstName]
8
+ end
9
+
10
+ def last_name
11
+ @last_name ||= @raw_data[:lastName]
12
+ end
13
+
14
+ def jersey_number
15
+ @jersey_number ||= @raw_data[:jerseyNumber]
16
+ end
17
+
18
+ def role
19
+ @role ||= @raw_data[:role]
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class ShootoutAttempt < Resource
6
+ def number
7
+ @number ||= @opts[:number]
8
+ end
9
+
10
+ def goal?
11
+ @goal ||= @raw_data[:isGoal]
12
+ end
13
+
14
+ def game_winner?
15
+ @game_winner ||= @raw_data[:isGameWinningGoal]
16
+ end
17
+
18
+ def shooter
19
+ @shooter ||= {
20
+ id: @raw_data[:shooter][:id],
21
+ first_name: @raw_data[:shooter][:firstName],
22
+ last_name: @raw_data[:shooter][:lastName],
23
+ jersey_number: @raw_data[:shooter][:jerseyNumber],
24
+ position: @raw_data[:shooter][:position],
25
+ }
26
+ end
27
+
28
+ def goalie
29
+ @goalie ||= {
30
+ id: @raw_data[:goalie][:id],
31
+ first_name: @raw_data[:goalie][:firstName],
32
+ last_name: @raw_data[:goalie][:lastName],
33
+ jersey_number: @raw_data[:goalie][:jerseyNumber],
34
+ position: @raw_data[:goalie][:position],
35
+ }
36
+ end
37
+
38
+ def shooting_team
39
+ @shooting_team ||= {
40
+ id: @raw_data[:shooterTeam][:id],
41
+ full_name: @raw_data[:shooterTeam][:name],
42
+ city: @raw_data[:shooterTeam][:city],
43
+ name: @raw_data[:shooterTeam][:nickname],
44
+ abbreviation: @raw_data[:shooterTeam][:abbreviation],
45
+ logo_url: @raw_data[:shooterTeam][:logo],
46
+ }
47
+ end
48
+
49
+ def goalie_team
50
+ @goalie_team ||= {
51
+ id: @opts[:opposing_team].id,
52
+ full_name: @opts[:opposing_team].name,
53
+ city: @opts[:opposing_team].city,
54
+ name: @opts[:opposing_team].name,
55
+ abbreviation: @opts[:opposing_team].abbreviation,
56
+ logo_url: @opts[:opposing_team].logo_url,
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module AhlScraper
4
+ module Games
5
+ class Skater < Resource
6
+ def id
7
+ @id ||= @raw_data[:id]
8
+ end
9
+
10
+ def first_name
11
+ @first_name ||= @raw_data[:first_name]
12
+ end
13
+
14
+ def last_name
15
+ @last_name ||= @raw_data[:last_name]
16
+ end
17
+
18
+ def position
19
+ @position ||= @raw_data[:position]
20
+ end
21
+
22
+ def jersey_number
23
+ @jersey_number ||= @raw_data[:number]
24
+ end
25
+
26
+ def birthdate
27
+ @birthdate ||= valid_birthdate? ? @raw_data[:birthdate] : nil
28
+ end
29
+
30
+ def current_age
31
+ @current_age ||= valid_birthdate? ? BirthdateHelper.new(birthdate).age_on_date(@opts[:game_date]) : nil
32
+ end
33
+
34
+ def team_id
35
+ @team_id ||= @raw_data[:team_id]
36
+ end
37
+
38
+ def team_abbreviation
39
+ @team_abbreviation ||= @raw_data[:team_abbreviation]
40
+ end
41
+
42
+ def starting
43
+ @starting ||= @raw_data[:starting]
44
+ end
45
+
46
+ def captaincy
47
+ @captaincy ||= @raw_data[:captaincy]
48
+ end
49
+
50
+ def home_team
51
+ @home_team ||= @raw_data[:home_team]
52
+ end
53
+
54
+ def stats
55
+ @stats ||= {
56
+ faceoff_attempts: @raw_data[:faceoff_attempts],
57
+ faceoff_wins: @raw_data[:faceoff_wins],
58
+ hits: @raw_data[:hits],
59
+ penalty_minutes: @raw_data[:penalty_minutes],
60
+ }
61
+ end
62
+
63
+ def shots
64
+ @shots ||= { sog_as: @raw_data[:sog_as] }
65
+ end
66
+
67
+ def scoring
68
+ @scoring ||= @opts[:scoring_statline]
69
+ end
70
+
71
+ def on_ice
72
+ @on_ice ||= @opts[:on_ice_statline]
73
+ end
74
+
75
+ def penalty
76
+ @penalty ||= @opts[:penalty_statline]
77
+ end
78
+
79
+ def penalty_shot
80
+ @penalty_shot ||= @opts[:penalty_shot_statline] || {}
81
+ end
82
+
83
+ def shootout
84
+ @shootout ||= @opts[:shootout_statline] || {}
85
+ end
86
+
87
+ private
88
+
89
+ def valid_birthdate?
90
+ @valid_birthdate ||= !@raw_data[:birthdate].empty? && @raw_data[:birthdate] != "0000-00-00"
91
+ end
92
+ end
93
+ end
94
+ end