class NpbApi::Player
Constants
- TEAMS
Attributes
note[RW]
Public Class Methods
all()
click to toggle source
# File lib/npb-api/player.rb, line 20 def self.all TEAMS.each_with_object([]) do |team, arr| arr << list(team: team) end.flatten end
list(team: nil)
click to toggle source
# File lib/npb-api/player.rb, line 11 def self.list(team: nil) raise UnknownTeamError unless TEAMS.include?(team) source(team).css('tr.rosterPlayer').each_with_object([]) do |row, arr| next if row.css('td.rosterRegister a').empty? row.css('td.rosterRegister a').attr('href').text =~ /\/players\/(\d+)\.html/ arr << new(id: $1, note: row.css('td.rosterdetail').text) end end
new(id: nil, note: nil)
click to toggle source
# File lib/npb-api/player.rb, line 38 def initialize(id: nil, note: nil) @id = id @note = note end
Private Class Methods
source(team)
click to toggle source
# File lib/npb-api/player.rb, line 26 def self.source(team) Nokogiri::HTML(open(url(team))) end
url(team)
click to toggle source
# File lib/npb-api/player.rb, line 30 def self.url(team) "http://bis.npb.or.jp/teams/rst_#{team}.html" end
Public Instance Methods
birthday()
click to toggle source
# File lib/npb-api/player.rb, line 63 def birthday detail[1].text.split(' ')[0] =~ /\A(\d{4})年(\d{1,2})月(\d{1,2})日生\z/ Date.new($1.to_i, $2.to_i, $3.to_i) end
career()
click to toggle source
# File lib/npb-api/player.rb, line 82 def career detail[2].text end
draft()
click to toggle source
# File lib/npb-api/player.rb, line 86 def draft detail[3].text end
hand()
click to toggle source
# File lib/npb-api/player.rb, line 78 def hand detail[1].text.split(' ')[3] end
height()
click to toggle source
# File lib/npb-api/player.rb, line 68 def height detail[1].text.split(' ')[1] =~ /\A身長(\d{3})cm\z/ $1.to_i end
kana()
click to toggle source
# File lib/npb-api/player.rb, line 59 def kana detail[0].text end
name()
click to toggle source
# File lib/npb-api/player.rb, line 47 def name header.css('.registerPlayer').text end
number()
click to toggle source
# File lib/npb-api/player.rb, line 51 def number header.css('.registerNo').text end
position()
click to toggle source
# File lib/npb-api/player.rb, line 55 def position header.css('.registerPosition').text end
team()
click to toggle source
# File lib/npb-api/player.rb, line 43 def team header.css('.registerTeam').text end
weight()
click to toggle source
# File lib/npb-api/player.rb, line 73 def weight detail[1].text.split(' ')[2] =~ /\A体重(\d{2,3})kg\z/ $1.to_i end
Private Instance Methods
detail()
click to toggle source
# File lib/npb-api/player.rb, line 104 def detail @detail ||= header.css('.registerDetail') end
header()
click to toggle source
# File lib/npb-api/player.rb, line 100 def header @header ||= source.css('#registerdivheader') end
source()
click to toggle source
# File lib/npb-api/player.rb, line 96 def source Nokogiri::HTML(open(url)) end
url()
click to toggle source
# File lib/npb-api/player.rb, line 92 def url "http://bis.npb.or.jp/players/#{@id}.html" end