class AhlScraper::PlayerGames::DataFetcher

Public Class Methods

new(player_id, season_id) click to toggle source
# File lib/ahl_scraper/fetchers/player_games/data_fetcher.rb, line 6
def initialize(player_id, season_id)
  @player_id = player_id
  @season_id = season_id
end

Public Instance Methods

call() click to toggle source
# File lib/ahl_scraper/fetchers/player_games/data_fetcher.rb, line 11
def call
  player_data = JSON.parse(player_data_without_bio, symbolize_names: true)

  player_data&.dig(:gameByGame, 0, :sections, 0, :data)&.map { |data| { **data, position: player_data[:info][:position] } }
end

Private Instance Methods

player_data_without_bio() click to toggle source
# File lib/ahl_scraper/fetchers/player_games/data_fetcher.rb, line 23
def player_data_without_bio
  data = Nokogiri::HTML(URI.parse(url).open).text[5..-2]
  bio = data[/\"bio"\:(.*?)\,\"teamName/m, 1]
  data.gsub(bio, "\"\"")
end
url() click to toggle source
# File lib/ahl_scraper/fetchers/player_games/data_fetcher.rb, line 19
def url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=player&player_id=#{@player_id}&season_id=#{@season_id}&site_id=3&key=ccb91f29d6744675&client_code=ahl&league_id=&lang=en&statsType=standard&callback=json" # rubocop:disable Layout/LineLength
end