class NpbApi::Stats::Fielding

Attributes

position[R]

Public Class Methods

list(team, league, year) click to toggle source
# File lib/npb-api/stats/fielding.rb, line 4
def self.list(team, league, year)
  raise UnknownTeamError unless TEAMS.include?(team)
  raise UnknownLeagueError unless LEAGUES.include?(league)
  position = ''
  source(team, league, year).css('#stdivmaintbl tr').each_with_object([]) do |row, arr|
    position = new_position(row) unless row.css('th.sthdfplayer').empty?
    arr << new(row, team, league, year, position) if ststats?(row)
  end
end
new(row, team, league, year, position) click to toggle source
# File lib/npb-api/stats/fielding.rb, line 30
def initialize(row, team, league, year, position)
  @row = row
  @team = team
  @league = league
  @year = year
  @position = position
end
url_key() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 22
def self.url_key
  'f'
end

Private Class Methods

new_position(row) click to toggle source
# File lib/npb-api/stats/fielding.rb, line 18
def self.new_position(row)
  row.css('th.sthdfplayer').text =~ /【(.+)】/; $1
end
ststats?(row) click to toggle source
# File lib/npb-api/stats/fielding.rb, line 14
def self.ststats?(row)
  !row.attributes['class'].nil? && row.attributes['class'].value == 'ststats'
end

Public Instance Methods

assists() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 50
def assists
  @row.children[9].children.text.to_i
end
double_plays() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 58
def double_plays
  @row.children[13].children.text.to_i
end
errors() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 54
def errors
  @row.children[11].children.text.to_i
end
fielding_average() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 67
def fielding_average
  @row.children[17].children.text.to_f
end
games() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 42
def games
  @row.children[5].children.text.to_i
end
passed_ball() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 62
def passed_ball
  value = @row.children[15].children.text
  value == '' ? nil : value.to_i
end
player() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 38
def player
  @row.children[3].children.text
end
put_outs() click to toggle source
# File lib/npb-api/stats/fielding.rb, line 46
def put_outs
  @row.children[7].children.text.to_i
end