class NpbApi::Player
Public Class Methods
new(id: '')
click to toggle source
# File lib/npb_api/player.rb, line 2 def initialize(id: '') @id = id @doc = Nokogiri::HTML(open("http://baseball.yahoo.co.jp/npb/player/#{id}/")).css('#profile') end
Public Instance Methods
info()
click to toggle source
# File lib/npb_api/player.rb, line 7 def info { id: @id.to_i, name: @doc.css('.NpbTeamTop').children.children[0].text, kana: kana, number: @doc.css('.NpbTeamTop').children.children.children[1].text, position: @doc.css('.NpbTeamTop').children.children.children[2].text, birthday: birthday, age: age, birthplace: @doc.css('tr')[0].children.children[-1].text, height: height, weight: weight, blood_type: blood_type, throw: _throw, bat: bat, draft_year: draft_year, draft_rank: draft_rank, total_years: total_years, carrier: @doc.css('tr')[3].children.children[-1].text, title: title } end
Private Instance Methods
_throw()
click to toggle source
NOTE: 予約語と重複するためアンスコをつけている
# File lib/npb_api/player.rb, line 63 def _throw @doc.css('tr')[1].children.children[-1].text =~ /\A(.)投げ.打ち\z/ $1 end
age()
click to toggle source
# File lib/npb_api/player.rb, line 42 def age @doc.css('tr')[0].children.children[2].text =~ /\A\d{4}年\d{1,2}月\d{1,2}日((\d{2})歳)\z/ $1.to_i end
bat()
click to toggle source
# File lib/npb_api/player.rb, line 68 def bat @doc.css('tr')[1].children.children[-1].text =~ /\A.投げ(.)打ち\z/ $1 end
birthday()
click to toggle source
# File lib/npb_api/player.rb, line 37 def birthday @doc.css('tr')[0].children.children[2].text =~ /\A(\d{4})年(\d{1,2})月(\d{1,2})日(\d{2}歳)\z/ Date.new($1.to_i, $2.to_i, $3.to_i) end
blood_type()
click to toggle source
# File lib/npb_api/player.rb, line 57 def blood_type @doc.css('tr')[1].children.children[1].text =~ /\A\d{3}cm\/\d{2,3}kg((.+))\z/ $1 end
draft_rank()
click to toggle source
# File lib/npb_api/player.rb, line 81 def draft_rank if @doc.css('tr')[2].children.children[1].text =~ /\A\d{4}年((.+))\z/ $1 else nil end end
draft_year()
click to toggle source
# File lib/npb_api/player.rb, line 73 def draft_year if @doc.css('tr')[2].children.children[1].text =~ /\A(\d{4})年(.+)\z/ $1.to_i else nil end end
height()
click to toggle source
# File lib/npb_api/player.rb, line 47 def height @doc.css('tr')[1].children.children[1].text =~ /\A(\d{3})cm\/\d{2,3}kg(.+)\z/ $1.to_i end
kana()
click to toggle source
# File lib/npb_api/player.rb, line 32 def kana @doc.css('.NpbTeamTop').children.children.children[0].text =~ /\A((.+))\z/ $1 end
title()
click to toggle source
# File lib/npb_api/player.rb, line 94 def title if @doc.css('tr')[4].children.children[-1].text == '-' nil else @doc.css('tr')[4].children.children[-1].text end end
total_years()
click to toggle source
# File lib/npb_api/player.rb, line 89 def total_years @doc.css('tr')[2].children.children[-1].text =~ /\A(\d+)年\z/ $1.to_i end
weight()
click to toggle source
# File lib/npb_api/player.rb, line 52 def weight @doc.css('tr')[1].children.children[1].text =~ /\A\d{3}cm\/(\d{2,3})kg(.+)\z/ $1.to_i end