class KnicksHistory::Scraper

Public Instance Methods

get_page() click to toggle source
# File lib/knicks_history/scraper.rb, line 3
def get_page
  Nokogiri::HTML(open("https://www.basketball-reference.com/teams/NYK/"))
end
make_seasons() click to toggle source
# File lib/knicks_history/scraper.rb, line 11
def make_seasons
  data_hash = {}
  scrape_seasons_index.each do |season|
    data_hash[:year] = season.css("th a").text.match(/\d{4}/).to_s
    data_hash[:wins] = season.css("td[data-stat = wins]").text
    data_hash[:losses] = season.css("td[data-stat = losses]").text
    data_hash[:win_percentage] = season.css("td[data-stat = win_loss_pct]").text
    if season.css("td[data-stat = off_rtg]").text == ""
      data_hash[:off_rating] = "N/A"
      data_hash[:def_rating] = "N/A"
    else
      data_hash[:off_rating] = season.css("td[data-stat = off_rtg]").text
      data_hash[:def_rating] = season.css("td[data-stat = def_rtg]").text
    end
    data_hash[:best_player_ws] = season.css("td[data-stat = top_ws]").text
    data_hash[:pace] = season.css("td[data-stat = pace]").text
    if season.css("td[data-stat = rank_team_playoffs]").text == ""
      data_hash[:playoff_results] = "Missed Playoffs"
    else
      data_hash[:playoff_results] = season.css("td[data-stat = rank_team_playoffs]").text
    end
    KnicksHistory::Season.new(data_hash)
  end
end
scrape_seasons_index() click to toggle source
# File lib/knicks_history/scraper.rb, line 7
def scrape_seasons_index
  self.get_page.css("#NYK tbody tr")
end