class NCAABasketball

Constants

NCAA_RPI_URL

Attributes

division_one_data[R]
standings_page[R]

Public Class Methods

new() click to toggle source
# File lib/ncaa_scrape.rb, line 8
def initialize
  @standings_page = Nokogiri::HTML(open(NCAA_RPI_URL))
  @division_one_data = team_names.zip(wins).to_h
end

Public Instance Methods

pick_five_total(*teams) click to toggle source
# File lib/ncaa_scrape.rb, line 21
def pick_five_total(*teams)
  teams.inject(0) { |total, team| total + team_wins(team) }
end
team_names() click to toggle source
# File lib/ncaa_scrape.rb, line 13
def team_names
  school_data.map { |row| row[2] }
end
team_wins(team_name) click to toggle source
# File lib/ncaa_scrape.rb, line 17
def team_wins(team_name)
  division_one_data.include?(team_name) ? division_one_data[team_name] : 0
end

Private Instance Methods

rows() click to toggle source
# File lib/ncaa_scrape.rb, line 27
def rows
  # skip the first row, which is the table header
  standings_page.xpath('//tr')[1..-1]
end
school_data() click to toggle source
# File lib/ncaa_scrape.rb, line 32
def school_data
  rows.map { |row| row.children.map(&:text) }
end
wins() click to toggle source
# File lib/ncaa_scrape.rb, line 36
def wins
  school_data.map { |row| row[4].split('-').first.to_i }
end