class NpbApi::Stats::Team

Attributes

year[R]

Public Class Methods

list(league, year) click to toggle source
# File lib/npb-api/stats/team.rb, line 8
def self.list(league, year)
  regular_reague = source(league, year).css('table.stdtblSubmain')[0]
  regular_reague.css('tr[align="center"]').each_with_object([]) do |row, arr|
    next if row.css('td.stdTeam').empty? # 行にチーム名が含まれていなかったらスキップ
    arr << new(row, league, year)
  end
end
new(row, league, year) click to toggle source
# File lib/npb-api/stats/team.rb, line 28
def initialize(row, league, year)
  @row = row
  @league = league
  @year = year
end

Private Class Methods

source(league, year) click to toggle source
# File lib/npb-api/stats/team.rb, line 16
def self.source(league, year)
  Nokogiri::HTML(open(url(league, year)))
end
url(league, year) click to toggle source
# File lib/npb-api/stats/team.rb, line 20
def self.url(league, year)
  "http://bis.npb.or.jp/#{year}/stats/std_#{league}.html"
end

Public Instance Methods

draws() click to toggle source
# File lib/npb-api/stats/team.rb, line 59
def draws
  @row.css('td.stdscore')[3].text.to_i
end
games() click to toggle source
# File lib/npb-api/stats/team.rb, line 47
def games
  @row.css('td.stdscore')[0].text.to_i
end
games_behind() click to toggle source
# File lib/npb-api/stats/team.rb, line 67
def games_behind
  @row.css('td.stdscore')[5].text
end
league() click to toggle source
# File lib/npb-api/stats/team.rb, line 34
def league
  case @league
  when 'c' then 'central'
  when 'p' then 'pacific'
  when 'e' then 'eastern'
  when 'w' then 'western'
  end
end
loses() click to toggle source
# File lib/npb-api/stats/team.rb, line 55
def loses
  @row.css('td.stdscore')[2].text.to_i
end
team() click to toggle source
# File lib/npb-api/stats/team.rb, line 43
def team
  @row.css('td.stdTeam').text.gsub(/ /, '')
end
winning_percentage() click to toggle source
# File lib/npb-api/stats/team.rb, line 63
def winning_percentage
  @row.css('td.stdscore')[4].text.to_f
end
wins() click to toggle source
# File lib/npb-api/stats/team.rb, line 51
def wins
  @row.css('td.stdscore')[1].text.to_i
end