Class: NpbApi::Player
- Inherits:
-
Object
- Object
- NpbApi::Player
- Defined in:
- lib/npb-api/player.rb
Constant Summary collapse
- TEAMS =
%w[g t c d db s h bs f m l e]
Instance Attribute Summary collapse
-
#note ⇒ Object
Returns the value of attribute note.
Class Method Summary collapse
Instance Method Summary collapse
- #birthday ⇒ Object
- #career ⇒ Object
- #draft ⇒ Object
- #hand ⇒ Object
- #height ⇒ Object
-
#initialize(id: nil, note: nil) ⇒ Player
constructor
A new instance of Player.
- #kana ⇒ Object
- #name ⇒ Object
- #number ⇒ Object
- #position ⇒ Object
- #team ⇒ Object
- #weight ⇒ Object
Constructor Details
#initialize(id: nil, note: nil) ⇒ Player
Returns a new instance of Player.
38 39 40 41 |
# File 'lib/npb-api/player.rb', line 38 def initialize(id: nil, note: nil) @id = id @note = note end |
Instance Attribute Details
#note ⇒ Object
Returns the value of attribute note.
36 37 38 |
# File 'lib/npb-api/player.rb', line 36 def note @note end |
Class Method Details
.all ⇒ Object
20 21 22 23 24 |
# 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) ⇒ Object
11 12 13 14 15 16 17 18 |
# 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 |
Instance Method Details
#birthday ⇒ Object
63 64 65 66 |
# 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 ⇒ Object
82 83 84 |
# File 'lib/npb-api/player.rb', line 82 def career detail[2].text end |
#draft ⇒ Object
86 87 88 |
# File 'lib/npb-api/player.rb', line 86 def draft detail[3].text end |
#hand ⇒ Object
78 79 80 |
# File 'lib/npb-api/player.rb', line 78 def hand detail[1].text.split(' ')[3] end |
#height ⇒ Object
68 69 70 71 |
# 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 ⇒ Object
59 60 61 |
# File 'lib/npb-api/player.rb', line 59 def kana detail[0].text end |
#name ⇒ Object
47 48 49 |
# File 'lib/npb-api/player.rb', line 47 def name header.css('.registerPlayer').text end |
#number ⇒ Object
51 52 53 |
# File 'lib/npb-api/player.rb', line 51 def number header.css('.registerNo').text end |
#position ⇒ Object
55 56 57 |
# File 'lib/npb-api/player.rb', line 55 def position header.css('.registerPosition').text end |
#team ⇒ Object
43 44 45 |
# File 'lib/npb-api/player.rb', line 43 def team header.css('.registerTeam').text end |
#weight ⇒ Object
73 74 75 76 |
# 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 |