Class: AhlScraper::Scoreboards::DataFetcher

Inherits:
Object
  • Object
show all
Defined in:
lib/ahl_scraper/fetchers/scoreboards/data_fetcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(start_date:, end_date:) ⇒ DataFetcher

Returns a new instance of DataFetcher.



6
7
8
9
# File 'lib/ahl_scraper/fetchers/scoreboards/data_fetcher.rb', line 6

def initialize(start_date:, end_date:)
  @start_date = start_date
  @end_date = end_date
end

Instance Method Details

#callObject



11
12
13
14
15
16
# File 'lib/ahl_scraper/fetchers/scoreboards/data_fetcher.rb', line 11

def call
  JSON.parse(Nokogiri::HTML(URI.parse(url).open).text[5..-2], symbolize_names: true)&.dig(:SiteKit, :Scorebar)&.filter do |game|
    game_date = Date.parse(game[:Date])
    game_date >= @start_date && game_date <= @end_date
  end
end