npb-api 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/console +1 -1
- data/lib/npb-api/player.rb +104 -0
- data/lib/npb-api/stats/base.rb +73 -0
- data/lib/npb-api/stats/fielding.rb +72 -0
- data/lib/npb-api/stats/hitting.rb +101 -0
- data/lib/npb-api/stats/pitching.rb +105 -0
- data/lib/npb-api/version.rb +3 -0
- data/lib/npb-api.rb +10 -0
- data/npb-api.gemspec +2 -2
- metadata +9 -9
- data/lib/npb/api/player.rb +0 -106
- data/lib/npb/api/stats/base.rb +0 -75
- data/lib/npb/api/stats/fielding.rb +0 -74
- data/lib/npb/api/stats/hitting.rb +0 -103
- data/lib/npb/api/stats/pitching.rb +0 -107
- data/lib/npb/api/version.rb +0 -5
- data/lib/npb/api.rb +0 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bbc59af7e23bc73477919912a160f4c8ad12373c
|
4
|
+
data.tar.gz: c232a1f92f6a1c148513f552eed34a1b7c519d1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6b71598ab0f1467289de03e4e51bf9a94280fb2d767ff9a9ecb1bcf2581d23907e66c180e915c867312412a0e37505d0fd2cc353746abdaa3cd201762b09ffa4
|
7
|
+
data.tar.gz: 1ea00f6687ab49c1d541a5fa3ba845da6ee77b9d5f59ca48f2e2d538bcd077346a0ab443d74767027b7cf6bd785d93ca75c75af1e0ae6155da365a9b29491053
|
data/bin/console
CHANGED
@@ -0,0 +1,104 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
class UnknownTeamError < StandardError; end
|
6
|
+
|
7
|
+
module NpbApi
|
8
|
+
class Player
|
9
|
+
TEAMS = %w[g t c d db s h bs f m l e]
|
10
|
+
|
11
|
+
def self.list(team: nil)
|
12
|
+
raise UnknownTeamError unless TEAMS.include?(team)
|
13
|
+
source(team).css('.rosterRegister a').each_with_object([]) do |link, arr|
|
14
|
+
link.attr('href') =~ /\/players\/(\d+)\.html/
|
15
|
+
arr << new(id: $1)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all
|
20
|
+
TEAMS.each_with_object([]) do |team, arr|
|
21
|
+
arr << list(team: team)
|
22
|
+
end.flatten
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.source(team)
|
26
|
+
Nokogiri::HTML(open(url(team)))
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.url(team)
|
30
|
+
"http://bis.npb.or.jp/teams/rst_#{team}.html"
|
31
|
+
end
|
32
|
+
|
33
|
+
private_class_method :source, :url
|
34
|
+
|
35
|
+
def initialize(id: nil)
|
36
|
+
@id = id
|
37
|
+
end
|
38
|
+
|
39
|
+
def team
|
40
|
+
header.css('.registerTeam').text
|
41
|
+
end
|
42
|
+
|
43
|
+
def name
|
44
|
+
header.css('.registerPlayer').text
|
45
|
+
end
|
46
|
+
|
47
|
+
def number
|
48
|
+
header.css('.registerNo').text
|
49
|
+
end
|
50
|
+
|
51
|
+
def position
|
52
|
+
header.css('.registerPosition').text
|
53
|
+
end
|
54
|
+
|
55
|
+
def kana
|
56
|
+
detail[0].text
|
57
|
+
end
|
58
|
+
|
59
|
+
def birthday
|
60
|
+
detail[1].text.split(' ')[0] =~ /\A(\d{4})年(\d{1,2})月(\d{1,2})日生\z/
|
61
|
+
Date.new($1.to_i, $2.to_i, $3.to_i)
|
62
|
+
end
|
63
|
+
|
64
|
+
def height
|
65
|
+
detail[1].text.split(' ')[1] =~ /\A身長(\d{3})cm\z/
|
66
|
+
$1.to_i
|
67
|
+
end
|
68
|
+
|
69
|
+
def weight
|
70
|
+
detail[1].text.split(' ')[2] =~ /\A体重(\d{2,3})kg\z/
|
71
|
+
$1.to_i
|
72
|
+
end
|
73
|
+
|
74
|
+
def hand
|
75
|
+
detail[1].text.split(' ')[3]
|
76
|
+
end
|
77
|
+
|
78
|
+
def career
|
79
|
+
detail[2].text
|
80
|
+
end
|
81
|
+
|
82
|
+
def draft
|
83
|
+
detail[3].text
|
84
|
+
end
|
85
|
+
|
86
|
+
private
|
87
|
+
|
88
|
+
def url
|
89
|
+
"http://bis.npb.or.jp/players/#{@id}.html"
|
90
|
+
end
|
91
|
+
|
92
|
+
def source
|
93
|
+
Nokogiri::HTML(open(url))
|
94
|
+
end
|
95
|
+
|
96
|
+
def header
|
97
|
+
@header ||= source.css('#registerdivheader')
|
98
|
+
end
|
99
|
+
|
100
|
+
def detail
|
101
|
+
@detail ||= header.css('.registerDetail')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
require 'open-uri'
|
3
|
+
require 'pry'
|
4
|
+
|
5
|
+
class UnknownLeagueError < StandardError; end
|
6
|
+
class UnknownTeamError < StandardError; end
|
7
|
+
|
8
|
+
module NpbApi
|
9
|
+
module Stats
|
10
|
+
class Base
|
11
|
+
TEAMS = %w[g t c d db s h bs f m l e]
|
12
|
+
LEAGUES = %w[central pacific eastern western]
|
13
|
+
TEAM_LEAGUES = [
|
14
|
+
{ team: 'g', leagues: %w[central eastern] },
|
15
|
+
{ team: 't', leagues: %w[central western] },
|
16
|
+
{ team: 'c', leagues: %w[central western] },
|
17
|
+
{ team: 'd', leagues: %w[central western] },
|
18
|
+
{ team: 'db', leagues: %w[central eastern] },
|
19
|
+
{ team: 's', leagues: %w[central eastern] },
|
20
|
+
{ team: 'h', leagues: %w[pacific western] },
|
21
|
+
{ team: 'bs', leagues: %w[pacific western] },
|
22
|
+
{ team: 'f', leagues: %w[pacific eastern] },
|
23
|
+
{ team: 'm', leagues: %w[pacific eastern] },
|
24
|
+
{ team: 'l', leagues: %w[pacific eastern] },
|
25
|
+
{ team: 'e', leagues: %w[pacific eastern] }
|
26
|
+
]
|
27
|
+
|
28
|
+
def self.list(team, league, year)
|
29
|
+
raise UnknownTeamError unless TEAMS.include?(team)
|
30
|
+
raise UnknownLeagueError unless LEAGUES.include?(league)
|
31
|
+
source(team, league, year).css('tr.ststats').each_with_object([]) do |row, arr|
|
32
|
+
arr << new(row, team, league, year)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.all(year)
|
37
|
+
TEAM_LEAGUES.each_with_object([]) do |team_leagues, arr|
|
38
|
+
team_leagues[:leagues].each do |league|
|
39
|
+
arr << list(team_leagues[:team], league, year)
|
40
|
+
end
|
41
|
+
end.flatten
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.source(team, league, year)
|
45
|
+
Nokogiri::HTML(open(url(team, league, year)))
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.url(team, league, year)
|
49
|
+
case league
|
50
|
+
when 'central', 'pacific'
|
51
|
+
"http://bis.npb.or.jp/#{year}/stats/id#{url_key}1_#{team}.html"
|
52
|
+
when 'eastern', 'western'
|
53
|
+
"http://bis.npb.or.jp/#{year}/stats/id#{url_key}2_#{team}.html"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.url_key
|
58
|
+
raise NotImplementedError
|
59
|
+
end
|
60
|
+
|
61
|
+
private_class_method :source, :url, :url_key
|
62
|
+
|
63
|
+
attr_reader :team, :league, :year
|
64
|
+
|
65
|
+
def initialize(row, team, league, year)
|
66
|
+
@row = row
|
67
|
+
@team = team
|
68
|
+
@league = league
|
69
|
+
@year = year
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module NpbApi
|
2
|
+
module Stats
|
3
|
+
class Fielding < Base
|
4
|
+
def self.list(team, league, year)
|
5
|
+
raise UnknownTeamError unless TEAMS.include?(team)
|
6
|
+
raise UnknownLeagueError unless LEAGUES.include?(league)
|
7
|
+
position = ''
|
8
|
+
source(team, league, year).css('#stdivmaintbl tr').each_with_object([]) do |row, arr|
|
9
|
+
position = new_position(row) unless row.css('th.sthdfplayer').empty?
|
10
|
+
arr << new(row, team, league, year, position) if ststats?(row)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.ststats?(row)
|
15
|
+
!row.attributes['class'].nil? && row.attributes['class'].value == 'ststats'
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.new_position(row)
|
19
|
+
row.css('th.sthdfplayer').text =~ /【(.+)】/; $1
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.url_key
|
23
|
+
'f'
|
24
|
+
end
|
25
|
+
|
26
|
+
private_class_method :ststats?, :new_position
|
27
|
+
|
28
|
+
attr_reader :position
|
29
|
+
|
30
|
+
def initialize(row, team, league, year, position)
|
31
|
+
@row = row
|
32
|
+
@team = team
|
33
|
+
@league = league
|
34
|
+
@year = year
|
35
|
+
@position = position
|
36
|
+
end
|
37
|
+
|
38
|
+
def player
|
39
|
+
@row.children[3].children.text
|
40
|
+
end
|
41
|
+
|
42
|
+
def games
|
43
|
+
@row.children[5].children.text.to_i
|
44
|
+
end
|
45
|
+
|
46
|
+
def put_outs
|
47
|
+
@row.children[7].children.text.to_i
|
48
|
+
end
|
49
|
+
|
50
|
+
def assists
|
51
|
+
@row.children[9].children.text.to_i
|
52
|
+
end
|
53
|
+
|
54
|
+
def errors
|
55
|
+
@row.children[11].children.text.to_i
|
56
|
+
end
|
57
|
+
|
58
|
+
def double_plays
|
59
|
+
@row.children[13].children.text.to_i
|
60
|
+
end
|
61
|
+
|
62
|
+
def passed_ball
|
63
|
+
value = @row.children[15].children.text
|
64
|
+
value == '' ? nil : value.to_i
|
65
|
+
end
|
66
|
+
|
67
|
+
def fielding_average
|
68
|
+
@row.children[17].children.text.to_f
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module NpbApi
|
2
|
+
module Stats
|
3
|
+
class Hitting < Base
|
4
|
+
def self.url_key
|
5
|
+
'b'
|
6
|
+
end
|
7
|
+
|
8
|
+
def player
|
9
|
+
@row.children[2].children.text
|
10
|
+
end
|
11
|
+
|
12
|
+
def games
|
13
|
+
@row.children[4].text.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def total_plate_appearances
|
17
|
+
@row.children[5].text.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def at_bats
|
21
|
+
@row.children[6].text.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def runs
|
25
|
+
@row.children[7].text.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def hits
|
29
|
+
@row.children[8].text.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def double
|
33
|
+
@row.children[9].text.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def triple
|
37
|
+
@row.children[10].text.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def home_runs
|
41
|
+
@row.children[11].text.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def total_bases
|
45
|
+
@row.children[13].text.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def runs_batted_in
|
49
|
+
@row.children[14].text.to_i
|
50
|
+
end
|
51
|
+
|
52
|
+
def stolen_bases
|
53
|
+
@row.children[15].text.to_i
|
54
|
+
end
|
55
|
+
|
56
|
+
def caught_stealing
|
57
|
+
@row.children[16].text.to_i
|
58
|
+
end
|
59
|
+
|
60
|
+
def sacrifice_hits
|
61
|
+
@row.children[17].text.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def sacrifice_flies
|
65
|
+
@row.children[18].text.to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
def bases_on_balls
|
69
|
+
@row.children[19].text.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def intentional_bases_on_balls
|
73
|
+
@row.children[21].text.to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
def hit_by_pitch
|
77
|
+
@row.children[22].text.to_i
|
78
|
+
end
|
79
|
+
|
80
|
+
def strikeouts
|
81
|
+
@row.children[23].text.to_i
|
82
|
+
end
|
83
|
+
|
84
|
+
def grounded_into_double_play
|
85
|
+
@row.children[24].text.to_i
|
86
|
+
end
|
87
|
+
|
88
|
+
def batting_average
|
89
|
+
@row.children[25].text.to_f
|
90
|
+
end
|
91
|
+
|
92
|
+
def slugging_percentage
|
93
|
+
@row.children[26].text.to_f
|
94
|
+
end
|
95
|
+
|
96
|
+
def on_base_percentage
|
97
|
+
@row.children[27].text.to_f
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
module NpbApi
|
2
|
+
module Stats
|
3
|
+
class Pitching < Base
|
4
|
+
def self.url_key
|
5
|
+
'p'
|
6
|
+
end
|
7
|
+
|
8
|
+
def player
|
9
|
+
@row.children[2].text
|
10
|
+
end
|
11
|
+
|
12
|
+
def games
|
13
|
+
@row.children[4].text.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
def wins
|
17
|
+
@row.children[5].text.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def loses
|
21
|
+
@row.children[6].text.to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def saves
|
25
|
+
@row.children[7].text.to_i
|
26
|
+
end
|
27
|
+
|
28
|
+
def holds
|
29
|
+
@row.children[8].text.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def hold_points
|
33
|
+
@row.children[9].text.to_i
|
34
|
+
end
|
35
|
+
|
36
|
+
def complete_games
|
37
|
+
@row.children[10].text.to_i
|
38
|
+
end
|
39
|
+
|
40
|
+
def shutouts
|
41
|
+
@row.children[11].text.to_i
|
42
|
+
end
|
43
|
+
|
44
|
+
def without_walking
|
45
|
+
@row.children[12].text.to_i
|
46
|
+
end
|
47
|
+
|
48
|
+
def winning_percentage
|
49
|
+
@row.children[14].text.to_f
|
50
|
+
end
|
51
|
+
|
52
|
+
def total_batters_faced
|
53
|
+
@row.children[15].text.to_i
|
54
|
+
end
|
55
|
+
|
56
|
+
def innings_pitched
|
57
|
+
(@row.children[16].text + @row.children[17].text).to_f
|
58
|
+
end
|
59
|
+
|
60
|
+
def hits
|
61
|
+
@row.children[18].text.to_i
|
62
|
+
end
|
63
|
+
|
64
|
+
def home_runs
|
65
|
+
@row.children[20].text.to_i
|
66
|
+
end
|
67
|
+
|
68
|
+
def walks
|
69
|
+
@row.children[21].text.to_i
|
70
|
+
end
|
71
|
+
|
72
|
+
def intentional_walks
|
73
|
+
@row.children[22].text.to_i
|
74
|
+
end
|
75
|
+
|
76
|
+
def hit_by_pitch
|
77
|
+
@row.children[23].text.to_i
|
78
|
+
end
|
79
|
+
|
80
|
+
def strikeouts
|
81
|
+
@row.children[24].text.to_i
|
82
|
+
end
|
83
|
+
|
84
|
+
def wild_pitches
|
85
|
+
@row.children[25].text.to_i
|
86
|
+
end
|
87
|
+
|
88
|
+
def balks
|
89
|
+
@row.children[26].text.to_i
|
90
|
+
end
|
91
|
+
|
92
|
+
def runs
|
93
|
+
@row.children[27].text.to_i
|
94
|
+
end
|
95
|
+
|
96
|
+
def earned_runs
|
97
|
+
@row.children[28].text.to_i
|
98
|
+
end
|
99
|
+
|
100
|
+
def earned_run_average
|
101
|
+
@row.children[29].text.to_f
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
data/lib/npb-api.rb
ADDED
data/npb-api.gemspec
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
lib = File.expand_path('../lib', __FILE__)
|
3
3
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'npb
|
4
|
+
require 'npb-api/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "npb-api"
|
8
|
-
spec.version =
|
8
|
+
spec.version = NpbApi::VERSION
|
9
9
|
spec.authors = ["ohtsuka"]
|
10
10
|
spec.email = ["t.o.0526@gmail.com"]
|
11
11
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npb-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ohtsuka
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -95,13 +95,13 @@ files:
|
|
95
95
|
- bin/console
|
96
96
|
- bin/setup
|
97
97
|
- circle.yml
|
98
|
-
- lib/npb
|
99
|
-
- lib/npb
|
100
|
-
- lib/npb
|
101
|
-
- lib/npb
|
102
|
-
- lib/npb
|
103
|
-
- lib/npb
|
104
|
-
- lib/npb
|
98
|
+
- lib/npb-api.rb
|
99
|
+
- lib/npb-api/player.rb
|
100
|
+
- lib/npb-api/stats/base.rb
|
101
|
+
- lib/npb-api/stats/fielding.rb
|
102
|
+
- lib/npb-api/stats/hitting.rb
|
103
|
+
- lib/npb-api/stats/pitching.rb
|
104
|
+
- lib/npb-api/version.rb
|
105
105
|
- npb-api.gemspec
|
106
106
|
homepage: http://example.com
|
107
107
|
licenses:
|
data/lib/npb/api/player.rb
DELETED
@@ -1,106 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
class UnknownTeamError < StandardError; end
|
6
|
-
|
7
|
-
module Npb
|
8
|
-
module Api
|
9
|
-
class Player
|
10
|
-
TEAMS = %w[g t c d db s h bs f m l e]
|
11
|
-
|
12
|
-
def self.list(team: nil)
|
13
|
-
raise UnknownTeamError unless TEAMS.include?(team)
|
14
|
-
source(team).css('.rosterRegister a').each_with_object([]) do |link, arr|
|
15
|
-
link.attr('href') =~ /\/players\/(\d+)\.html/
|
16
|
-
arr << new(id: $1)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def self.all
|
21
|
-
TEAMS.each_with_object([]) do |team, arr|
|
22
|
-
arr << list(team: team)
|
23
|
-
end.flatten
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.source(team)
|
27
|
-
Nokogiri::HTML(open(url(team)))
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.url(team)
|
31
|
-
"http://bis.npb.or.jp/teams/rst_#{team}.html"
|
32
|
-
end
|
33
|
-
|
34
|
-
private_class_method :source, :url
|
35
|
-
|
36
|
-
def initialize(id: nil)
|
37
|
-
@id = id
|
38
|
-
end
|
39
|
-
|
40
|
-
def team
|
41
|
-
header.css('.registerTeam').text
|
42
|
-
end
|
43
|
-
|
44
|
-
def name
|
45
|
-
header.css('.registerPlayer').text
|
46
|
-
end
|
47
|
-
|
48
|
-
def number
|
49
|
-
header.css('.registerNo').text
|
50
|
-
end
|
51
|
-
|
52
|
-
def position
|
53
|
-
header.css('.registerPosition').text
|
54
|
-
end
|
55
|
-
|
56
|
-
def kana
|
57
|
-
detail[0].text
|
58
|
-
end
|
59
|
-
|
60
|
-
def birthday
|
61
|
-
detail[1].text.split(' ')[0] =~ /\A(\d{4})年(\d{1,2})月(\d{1,2})日生\z/
|
62
|
-
Date.new($1.to_i, $2.to_i, $3.to_i)
|
63
|
-
end
|
64
|
-
|
65
|
-
def height
|
66
|
-
detail[1].text.split(' ')[1] =~ /\A身長(\d{3})cm\z/
|
67
|
-
$1.to_i
|
68
|
-
end
|
69
|
-
|
70
|
-
def weight
|
71
|
-
detail[1].text.split(' ')[2] =~ /\A体重(\d{2,3})kg\z/
|
72
|
-
$1.to_i
|
73
|
-
end
|
74
|
-
|
75
|
-
def hand
|
76
|
-
detail[1].text.split(' ')[3]
|
77
|
-
end
|
78
|
-
|
79
|
-
def career
|
80
|
-
detail[2].text
|
81
|
-
end
|
82
|
-
|
83
|
-
def draft
|
84
|
-
detail[3].text
|
85
|
-
end
|
86
|
-
|
87
|
-
private
|
88
|
-
|
89
|
-
def url
|
90
|
-
"http://bis.npb.or.jp/players/#{@id}.html"
|
91
|
-
end
|
92
|
-
|
93
|
-
def source
|
94
|
-
Nokogiri::HTML(open(url))
|
95
|
-
end
|
96
|
-
|
97
|
-
def header
|
98
|
-
@header ||= source.css('#registerdivheader')
|
99
|
-
end
|
100
|
-
|
101
|
-
def detail
|
102
|
-
@detail ||= header.css('.registerDetail')
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
data/lib/npb/api/stats/base.rb
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
require 'open-uri'
|
3
|
-
require 'pry'
|
4
|
-
|
5
|
-
class UnknownLeagueError < StandardError; end
|
6
|
-
class UnknownTeamError < StandardError; end
|
7
|
-
|
8
|
-
module Npb
|
9
|
-
module Api
|
10
|
-
module Stats
|
11
|
-
class Base
|
12
|
-
TEAMS = %w[g t c d db s h bs f m l e]
|
13
|
-
LEAGUES = %w[central pacific eastern western]
|
14
|
-
TEAM_LEAGUES = [
|
15
|
-
{ team: 'g', leagues: %w[central eastern] },
|
16
|
-
{ team: 't', leagues: %w[central western] },
|
17
|
-
{ team: 'c', leagues: %w[central western] },
|
18
|
-
{ team: 'd', leagues: %w[central western] },
|
19
|
-
{ team: 'db', leagues: %w[central eastern] },
|
20
|
-
{ team: 's', leagues: %w[central eastern] },
|
21
|
-
{ team: 'h', leagues: %w[pacific western] },
|
22
|
-
{ team: 'bs', leagues: %w[pacific western] },
|
23
|
-
{ team: 'f', leagues: %w[pacific eastern] },
|
24
|
-
{ team: 'm', leagues: %w[pacific eastern] },
|
25
|
-
{ team: 'l', leagues: %w[pacific eastern] },
|
26
|
-
{ team: 'e', leagues: %w[pacific eastern] }
|
27
|
-
]
|
28
|
-
|
29
|
-
def self.list(team, league, year)
|
30
|
-
raise UnknownTeamError unless TEAMS.include?(team)
|
31
|
-
raise UnknownLeagueError unless LEAGUES.include?(league)
|
32
|
-
source(team, league, year).css('tr.ststats').each_with_object([]) do |row, arr|
|
33
|
-
arr << new(row, team, league, year)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def self.all(year)
|
38
|
-
TEAM_LEAGUES.each_with_object([]) do |team_leagues, arr|
|
39
|
-
team_leagues[:leagues].each do |league|
|
40
|
-
arr << list(team_leagues[:team], league, year)
|
41
|
-
end
|
42
|
-
end.flatten
|
43
|
-
end
|
44
|
-
|
45
|
-
def self.source(team, league, year)
|
46
|
-
Nokogiri::HTML(open(url(team, league, year)))
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.url(team, league, year)
|
50
|
-
case league
|
51
|
-
when 'central', 'pacific'
|
52
|
-
"http://bis.npb.or.jp/#{year}/stats/id#{url_key}1_#{team}.html"
|
53
|
-
when 'eastern', 'western'
|
54
|
-
"http://bis.npb.or.jp/#{year}/stats/id#{url_key}2_#{team}.html"
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.url_key
|
59
|
-
raise NotImplementedError
|
60
|
-
end
|
61
|
-
|
62
|
-
private_class_method :source, :url, :url_key
|
63
|
-
|
64
|
-
attr_reader :team, :league, :year
|
65
|
-
|
66
|
-
def initialize(row, team, league, year)
|
67
|
-
@row = row
|
68
|
-
@team = team
|
69
|
-
@league = league
|
70
|
-
@year = year
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Npb
|
2
|
-
module Api
|
3
|
-
module Stats
|
4
|
-
class Fielding < Base
|
5
|
-
def self.list(team, league, year)
|
6
|
-
raise UnknownTeamError unless TEAMS.include?(team)
|
7
|
-
raise UnknownLeagueError unless LEAGUES.include?(league)
|
8
|
-
position = ''
|
9
|
-
source(team, league, year).css('#stdivmaintbl tr').each_with_object([]) do |row, arr|
|
10
|
-
position = new_position(row) unless row.css('th.sthdfplayer').empty?
|
11
|
-
arr << new(row, team, league, year, position) if ststats?(row)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.ststats?(row)
|
16
|
-
!row.attributes['class'].nil? && row.attributes['class'].value == 'ststats'
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.new_position(row)
|
20
|
-
row.css('th.sthdfplayer').text =~ /【(.+)】/; $1
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.url_key
|
24
|
-
'f'
|
25
|
-
end
|
26
|
-
|
27
|
-
private_class_method :ststats?, :new_position
|
28
|
-
|
29
|
-
attr_reader :position
|
30
|
-
|
31
|
-
def initialize(row, team, league, year, position)
|
32
|
-
@row = row
|
33
|
-
@team = team
|
34
|
-
@league = league
|
35
|
-
@year = year
|
36
|
-
@position = position
|
37
|
-
end
|
38
|
-
|
39
|
-
def player
|
40
|
-
@row.children[3].children.text
|
41
|
-
end
|
42
|
-
|
43
|
-
def games
|
44
|
-
@row.children[5].children.text.to_i
|
45
|
-
end
|
46
|
-
|
47
|
-
def put_outs
|
48
|
-
@row.children[7].children.text.to_i
|
49
|
-
end
|
50
|
-
|
51
|
-
def assists
|
52
|
-
@row.children[9].children.text.to_i
|
53
|
-
end
|
54
|
-
|
55
|
-
def errors
|
56
|
-
@row.children[11].children.text.to_i
|
57
|
-
end
|
58
|
-
|
59
|
-
def double_plays
|
60
|
-
@row.children[13].children.text.to_i
|
61
|
-
end
|
62
|
-
|
63
|
-
def passed_ball
|
64
|
-
value = @row.children[15].children.text
|
65
|
-
value == '' ? nil : value.to_i
|
66
|
-
end
|
67
|
-
|
68
|
-
def fielding_average
|
69
|
-
@row.children[17].children.text.to_f
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,103 +0,0 @@
|
|
1
|
-
module Npb
|
2
|
-
module Api
|
3
|
-
module Stats
|
4
|
-
class Hitting < Base
|
5
|
-
def self.url_key
|
6
|
-
'b'
|
7
|
-
end
|
8
|
-
|
9
|
-
def player
|
10
|
-
@row.children[2].children.text
|
11
|
-
end
|
12
|
-
|
13
|
-
def games
|
14
|
-
@row.children[4].text.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def total_plate_appearances
|
18
|
-
@row.children[5].text.to_i
|
19
|
-
end
|
20
|
-
|
21
|
-
def at_bats
|
22
|
-
@row.children[6].text.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def runs
|
26
|
-
@row.children[7].text.to_i
|
27
|
-
end
|
28
|
-
|
29
|
-
def hits
|
30
|
-
@row.children[8].text.to_i
|
31
|
-
end
|
32
|
-
|
33
|
-
def double
|
34
|
-
@row.children[9].text.to_i
|
35
|
-
end
|
36
|
-
|
37
|
-
def triple
|
38
|
-
@row.children[10].text.to_i
|
39
|
-
end
|
40
|
-
|
41
|
-
def home_runs
|
42
|
-
@row.children[11].text.to_i
|
43
|
-
end
|
44
|
-
|
45
|
-
def total_bases
|
46
|
-
@row.children[13].text.to_i
|
47
|
-
end
|
48
|
-
|
49
|
-
def runs_batted_in
|
50
|
-
@row.children[14].text.to_i
|
51
|
-
end
|
52
|
-
|
53
|
-
def stolen_bases
|
54
|
-
@row.children[15].text.to_i
|
55
|
-
end
|
56
|
-
|
57
|
-
def caught_stealing
|
58
|
-
@row.children[16].text.to_i
|
59
|
-
end
|
60
|
-
|
61
|
-
def sacrifice_hits
|
62
|
-
@row.children[17].text.to_i
|
63
|
-
end
|
64
|
-
|
65
|
-
def sacrifice_flies
|
66
|
-
@row.children[18].text.to_i
|
67
|
-
end
|
68
|
-
|
69
|
-
def bases_on_balls
|
70
|
-
@row.children[19].text.to_i
|
71
|
-
end
|
72
|
-
|
73
|
-
def intentional_bases_on_balls
|
74
|
-
@row.children[21].text.to_i
|
75
|
-
end
|
76
|
-
|
77
|
-
def hit_by_pitch
|
78
|
-
@row.children[22].text.to_i
|
79
|
-
end
|
80
|
-
|
81
|
-
def strikeouts
|
82
|
-
@row.children[23].text.to_i
|
83
|
-
end
|
84
|
-
|
85
|
-
def grounded_into_double_play
|
86
|
-
@row.children[24].text.to_i
|
87
|
-
end
|
88
|
-
|
89
|
-
def batting_average
|
90
|
-
@row.children[25].text.to_f
|
91
|
-
end
|
92
|
-
|
93
|
-
def slugging_percentage
|
94
|
-
@row.children[26].text.to_f
|
95
|
-
end
|
96
|
-
|
97
|
-
def on_base_percentage
|
98
|
-
@row.children[27].text.to_f
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
module Npb
|
2
|
-
module Api
|
3
|
-
module Stats
|
4
|
-
class Pitching < Base
|
5
|
-
def self.url_key
|
6
|
-
'p'
|
7
|
-
end
|
8
|
-
|
9
|
-
def player
|
10
|
-
@row.children[2].text
|
11
|
-
end
|
12
|
-
|
13
|
-
def games
|
14
|
-
@row.children[4].text.to_i
|
15
|
-
end
|
16
|
-
|
17
|
-
def wins
|
18
|
-
@row.children[5].text.to_i
|
19
|
-
end
|
20
|
-
|
21
|
-
def loses
|
22
|
-
@row.children[6].text.to_i
|
23
|
-
end
|
24
|
-
|
25
|
-
def saves
|
26
|
-
@row.children[7].text.to_i
|
27
|
-
end
|
28
|
-
|
29
|
-
def holds
|
30
|
-
@row.children[8].text.to_i
|
31
|
-
end
|
32
|
-
|
33
|
-
def hold_points
|
34
|
-
@row.children[9].text.to_i
|
35
|
-
end
|
36
|
-
|
37
|
-
def complete_games
|
38
|
-
@row.children[10].text.to_i
|
39
|
-
end
|
40
|
-
|
41
|
-
def shutouts
|
42
|
-
@row.children[11].text.to_i
|
43
|
-
end
|
44
|
-
|
45
|
-
def without_walking
|
46
|
-
@row.children[12].text.to_i
|
47
|
-
end
|
48
|
-
|
49
|
-
def winning_percentage
|
50
|
-
@row.children[14].text.to_f
|
51
|
-
end
|
52
|
-
|
53
|
-
def total_batters_faced
|
54
|
-
@row.children[15].text.to_i
|
55
|
-
end
|
56
|
-
|
57
|
-
def innings_pitched
|
58
|
-
(@row.children[16].text + @row.children[17].text).to_f
|
59
|
-
end
|
60
|
-
|
61
|
-
def hits
|
62
|
-
@row.children[18].text.to_i
|
63
|
-
end
|
64
|
-
|
65
|
-
def home_runs
|
66
|
-
@row.children[20].text.to_i
|
67
|
-
end
|
68
|
-
|
69
|
-
def walks
|
70
|
-
@row.children[21].text.to_i
|
71
|
-
end
|
72
|
-
|
73
|
-
def intentional_walks
|
74
|
-
@row.children[22].text.to_i
|
75
|
-
end
|
76
|
-
|
77
|
-
def hit_by_pitch
|
78
|
-
@row.children[23].text.to_i
|
79
|
-
end
|
80
|
-
|
81
|
-
def strikeouts
|
82
|
-
@row.children[24].text.to_i
|
83
|
-
end
|
84
|
-
|
85
|
-
def wild_pitches
|
86
|
-
@row.children[25].text.to_i
|
87
|
-
end
|
88
|
-
|
89
|
-
def balks
|
90
|
-
@row.children[26].text.to_i
|
91
|
-
end
|
92
|
-
|
93
|
-
def runs
|
94
|
-
@row.children[27].text.to_i
|
95
|
-
end
|
96
|
-
|
97
|
-
def earned_runs
|
98
|
-
@row.children[28].text.to_i
|
99
|
-
end
|
100
|
-
|
101
|
-
def earned_run_average
|
102
|
-
@row.children[29].text.to_f
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
data/lib/npb/api/version.rb
DELETED