class NpbApi::Stats::Base

Constants

LEAGUES
TEAMS
TEAM_LEAGUES

Attributes

league[R]
team[R]
year[R]

Public Class Methods

all(year) click to toggle source
# File lib/npb-api/stats/base.rb, line 36
def self.all(year)
  TEAM_LEAGUES.each_with_object([]) do |team_leagues, arr|
    team_leagues[:leagues].each do |league|
      arr << list(team_leagues[:team], league, year)
    end
  end.flatten
end
list(team, league, year) click to toggle source
# File lib/npb-api/stats/base.rb, line 28
def self.list(team, league, year)
  raise UnknownTeamError unless TEAMS.include?(team)
  raise UnknownLeagueError unless LEAGUES.include?(league)
  source(team, league, year).css('tr.ststats').each_with_object([]) do |row, arr|
    arr << new(row, team, league, year)
  end
end
new(row, team, league, year) click to toggle source
# File lib/npb-api/stats/base.rb, line 65
def initialize(row, team, league, year)
  @row = row
  @team = team
  @league = league
  @year = year
end

Private Class Methods

source(team, league, year) click to toggle source
# File lib/npb-api/stats/base.rb, line 44
def self.source(team, league, year)
  Nokogiri::HTML(open(url(team, league, year)))
end
url(team, league, year) click to toggle source
# File lib/npb-api/stats/base.rb, line 48
def self.url(team, league, year)
  case league
  when 'central', 'pacific'
    "http://bis.npb.or.jp/#{year}/stats/id#{url_key}1_#{team}.html"
  when 'eastern', 'western'
    "http://bis.npb.or.jp/#{year}/stats/id#{url_key}2_#{team}.html"
  end
end
url_key() click to toggle source
# File lib/npb-api/stats/base.rb, line 57
def self.url_key
  raise NotImplementedError
end