class AhlScraper::TeamRosterDataFetcher

Public Class Methods

new(team_id, season_id) click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 5
def initialize(team_id, season_id)
  @team_id = team_id
  @season_id = season_id
end

Public Instance Methods

call() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 10
def call
  fetch_roster_data
  merge_positional_data
  merge_roster_data
  merge_all_data
end

Private Instance Methods

defencemen_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 27
def defencemen_data
  @defencemen_data ||= JSON.parse(Nokogiri::HTML(URI.parse(defencemen_url).open).text[5..-2], symbolize_names: true).dig(0, :sections, 0, :data)
end
defencemen_url() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 59
def defencemen_url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=players&season=#{@season_id}&team=#{@team_id}&position=defencemen&rookies=0&statsType=standard&rosterstatus=undefined&site_id=3&first=0&limit=20&sort=points&league_id=4&lang=en&division=-1&key=50c2cd9b5e18e390&client_code=ahl&league_id=4&callback=json" # rubocop:disable Layout/LineLength
end
fetch_roster_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 19
def fetch_roster_data
  @roster_data = JSON.parse(Nokogiri::HTML(URI.parse(roster_url).open).text[5..-2], symbolize_names: true)
end
forward_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 23
def forward_data
  @forward_data ||= JSON.parse(Nokogiri::HTML(URI.parse(forwards_url).open).text[5..-2], symbolize_names: true).dig(0, :sections, 0, :data)
end
forwards_url() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 55
def forwards_url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=players&season=#{@season_id}&team=#{@team_id}&position=skaters&rookies=0&statsType=standard&rosterstatus=undefined&site_id=3&first=0&limit=20&sort=points&league_id=4&lang=en&division=-1&key=50c2cd9b5e18e390&client_code=ahl&league_id=4&callback=json" # rubocop:disable Layout/LineLength
end
goalie_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 31
def goalie_data
  @goalie_data ||= JSON.parse(Nokogiri::HTML(URI.parse(goalies_url).open).text[5..-2], symbolize_names: true).dig(0, :sections, 0, :data)
end
goalies_url() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 63
def goalies_url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=players&season=#{@season_id}&team=#{@team_id}&position=goalies&rookies=0&statsType=standard&rosterstatus=undefined&site_id=3&first=0&limit=20&sort=gaa&league_id=4&lang=en&division=-1&qualified=all&key=50c2cd9b5e18e390&client_code=ahl&league_id=4&callback=json" # rubocop:disable Layout/LineLength
end
merge_all_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 45
def merge_all_data
  @player_bio_data = @player_data.map do |player|
    { bio: player, stats: @positional_data[player[:row][:player_id]] }
  end
end
merge_positional_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 39
def merge_positional_data
  @positional_data = (forward_data + defencemen_data + goalie_data).filter { |player| !player[:row][:player_id].nil? }
    .map { |player| [player[:row][:player_id], player] }
    .to_h
end
merge_roster_data() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 35
def merge_roster_data
  @player_data = @roster_data.dig(:roster, 0, :sections)[0..2].map { |players| players[:data] }.flatten
end
roster_url() click to toggle source
# File lib/ahl_scraper/fetchers/team_roster_data_fetcher.rb, line 51
def roster_url
  "https://lscluster.hockeytech.com/feed/index.php?feed=statviewfeed&view=roster&team_id=#{@team_id}&season_id=#{@season_id}&key=50c2cd9b5e18e390&client_code=ahl&site_id=3&league_id=4&lang=en&callback=json" # rubocop:disable Layout/LineLength
end