Class: NpbApi::Stats::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/npb-api/stats/base.rb

Direct Known Subclasses

Fielding, Hitting, Pitching

Constant Summary collapse

TEAMS =
%w[g t c d db s h bs f m l e]
LEAGUES =
%w[central pacific eastern western]
TEAM_LEAGUES =
{ team: 'g',  leagues: %w[central eastern] },
{ team: 't',  leagues: %w[central western] },
{ team: 'c',  leagues: %w[central western] },
{ team: 'd',  leagues: %w[central western] },
{ team: 'db', leagues: %w[central eastern] },
{ team: 's',  leagues: %w[central eastern] },
{ team: 'h',  leagues: %w[pacific western] },
{ team: 'bs', leagues: %w[pacific western] },
{ team: 'f',  leagues: %w[pacific eastern] },
{ team: 'm',  leagues: %w[pacific eastern] },
{ team: 'l',  leagues: %w[pacific eastern] },
{ team: 'e',  leagues: %w[pacific eastern] }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row, team, league, year) ⇒ Base

Returns a new instance of Base.



65
66
67
68
69
70
# File 'lib/npb-api/stats/base.rb', line 65

def initialize(row, team, league, year)
  @row = row
  @team = team
  @league = league
  @year = year
end

Instance Attribute Details

#leagueObject (readonly)

Returns the value of attribute league.



63
64
65
# File 'lib/npb-api/stats/base.rb', line 63

def league
  @league
end

#teamObject (readonly)

Returns the value of attribute team.



63
64
65
# File 'lib/npb-api/stats/base.rb', line 63

def team
  @team
end

#yearObject (readonly)

Returns the value of attribute year.



63
64
65
# File 'lib/npb-api/stats/base.rb', line 63

def year
  @year
end

Class Method Details

.all(year) ⇒ Object



36
37
38
39
40
41
42
# 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) ⇒ Object

Raises:



28
29
30
31
32
33
34
# 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