npb_api 0.2.1 → 0.3.0
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/lib/npb_api/game.rb +2 -2
- data/lib/npb_api/hitting_stats.rb +38 -23
- data/lib/npb_api/pitching_stats.rb +28 -13
- data/lib/npb_api/player.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6d1baf5a1597fb8cedf2d72dc2a530f2f05f468c
|
4
|
+
data.tar.gz: 4a5fd49ffc2a2a608060f0e635c5e26228f5ab27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 78e35d9ffce8239f2a7f3ec39040d276541238cc8ef9bc10bc3fae387535ea75f65e863f7e69c71ba98c12514e671147dbdf92cf43ad549ea7b09a5d5ce9385f
|
7
|
+
data.tar.gz: 49d9bb924687f7589436d1a8224f5f1a92571e38d08a5f34d9d51444ff77038adcfea6a11e8f6309b01d78080624c3556025657da36f8af0eba6c081dfd9fc40
|
data/lib/npb_api/game.rb
CHANGED
@@ -7,7 +7,7 @@ class NpbApi::Game
|
|
7
7
|
|
8
8
|
def away
|
9
9
|
{
|
10
|
-
id: @id,
|
10
|
+
id: @id.to_i,
|
11
11
|
status: status,
|
12
12
|
team: @doc.css('.column-right.clearfix i').text,
|
13
13
|
score: away_score,
|
@@ -19,7 +19,7 @@ class NpbApi::Game
|
|
19
19
|
|
20
20
|
def home
|
21
21
|
{
|
22
|
-
id: @id,
|
22
|
+
id: @id.to_i,
|
23
23
|
status: status,
|
24
24
|
team: @doc.css('.column-left.clearfix i').text,
|
25
25
|
score: home_score,
|
@@ -1,24 +1,27 @@
|
|
1
1
|
class NpbApi::HittingStats
|
2
2
|
def initialize(date: '', id: '')
|
3
3
|
@date = date
|
4
|
-
@game_id = date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id
|
4
|
+
@game_id = (date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id).to_i
|
5
5
|
@url = "http://baseball.yahoo.co.jp/npb/game/#{@game_id}/stats"
|
6
6
|
@doc = TableExtraction.new(url: @url, klass: 'yjS').doc
|
7
7
|
end
|
8
8
|
|
9
9
|
def away
|
10
|
-
|
11
|
-
stats(@doc[0]).map { |s| s.merge({ team: team }) }
|
10
|
+
stats(:away)
|
12
11
|
end
|
13
12
|
|
14
13
|
def home
|
15
|
-
|
16
|
-
stats(@doc[1]).map { |s| s.merge({ team: team }) }
|
14
|
+
stats(:home)
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
18
|
|
21
|
-
def stats(
|
19
|
+
def stats(home_or_away)
|
20
|
+
doc =
|
21
|
+
case home_or_away
|
22
|
+
when :home then @doc[1]
|
23
|
+
when :away then @doc[0]
|
24
|
+
end
|
22
25
|
rows = doc.css('tr')
|
23
26
|
rows.shift
|
24
27
|
rows.pop
|
@@ -28,10 +31,9 @@ class NpbApi::HittingStats
|
|
28
31
|
arr << {
|
29
32
|
date: @date,
|
30
33
|
game_id: @game_id,
|
31
|
-
|
34
|
+
order: order,
|
32
35
|
starting_lineup: starting_lineup?(row),
|
33
36
|
position: position(row),
|
34
|
-
player: row.children[3].text,
|
35
37
|
player_id: player_id(row),
|
36
38
|
batting_average: row.children[5].text.to_f,
|
37
39
|
at_bats: row.children[7].text.to_i,
|
@@ -39,20 +41,21 @@ class NpbApi::HittingStats
|
|
39
41
|
hits: row.children[11].text.to_i,
|
40
42
|
runs_batted_in: row.children[13].text.to_i,
|
41
43
|
strikeouts: row.children[15].text.to_i,
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
44
|
+
sacrifice_hits: row.children[19].text.to_i,
|
45
|
+
stolen_bases: row.children[21].text.to_i,
|
46
|
+
errors: row.children[23].text.to_i,
|
47
|
+
home_runs: row.children[25].text.to_i,
|
48
|
+
bases_on_balls: bases_on_balls(row),
|
49
|
+
intentional_bases_on_balls: intentional_bases_on_balls(row),
|
50
|
+
hit_by_pitch: hit_by_pitch(row),
|
51
|
+
sacrifice_flies: sacrifice_flies(row),
|
52
|
+
double_plays: double_plays(row),
|
53
|
+
plate_appearances: plate_appearances(row),
|
54
|
+
doubles: doubles(row),
|
55
|
+
triples: triples(row),
|
56
|
+
total_bases: total_bases(row),
|
57
|
+
details: details(row),
|
58
|
+
team_id: team_id(home_or_away)
|
56
59
|
}
|
57
60
|
end
|
58
61
|
end
|
@@ -72,7 +75,7 @@ class NpbApi::HittingStats
|
|
72
75
|
|
73
76
|
def player_id(row)
|
74
77
|
row.children[3].css('a').attribute('href').value =~ /\A\/npb\/player\?id=(\d+)\z/
|
75
|
-
$1
|
78
|
+
$1.to_i
|
76
79
|
end
|
77
80
|
|
78
81
|
def bases_on_balls(row)
|
@@ -131,4 +134,16 @@ class NpbApi::HittingStats
|
|
131
134
|
hash.merge!({ twelfth: row.children[38].text }) if row.children[38]
|
132
135
|
hash
|
133
136
|
end
|
137
|
+
|
138
|
+
def team_id(home_or_away)
|
139
|
+
scoreboard =
|
140
|
+
case home_or_away
|
141
|
+
when :home
|
142
|
+
TableExtraction.new(url: @url, klass: 'scoreboard').doc[1]
|
143
|
+
when :away
|
144
|
+
TableExtraction.new(url: @url, klass: 'scoreboard').doc[0]
|
145
|
+
end
|
146
|
+
scoreboard.css('td.tn').children[0].attribute('href').value =~ /\A\/npb\/teams\/(\d+)\/\z/
|
147
|
+
$1.to_i
|
148
|
+
end
|
134
149
|
end
|
@@ -1,24 +1,27 @@
|
|
1
1
|
class NpbApi::PitchingStats
|
2
2
|
def initialize(date: '', id: '')
|
3
3
|
@date = date
|
4
|
-
@game_id = date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id
|
4
|
+
@game_id = (date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id).to_i
|
5
5
|
@url = "http://baseball.yahoo.co.jp/npb/game/#{@game_id}/stats"
|
6
6
|
@doc = TableExtraction.new(url: @url).doc
|
7
7
|
end
|
8
8
|
|
9
9
|
def away
|
10
|
-
|
11
|
-
stats(@doc[-2]).map { |s| s.merge({ team: team }) }
|
10
|
+
stats(:away)
|
12
11
|
end
|
13
12
|
|
14
13
|
def home
|
15
|
-
|
16
|
-
stats(@doc[-1]).map { |s| s.merge({ team: team }) }
|
14
|
+
stats(:home)
|
17
15
|
end
|
18
16
|
|
19
17
|
private
|
20
18
|
|
21
|
-
def stats(
|
19
|
+
def stats(home_or_away)
|
20
|
+
doc =
|
21
|
+
case home_or_away
|
22
|
+
when :home then @doc[-1]
|
23
|
+
when :away then @doc[-2]
|
24
|
+
end
|
22
25
|
rows = doc.css('tr')
|
23
26
|
rows.shift
|
24
27
|
order = 0
|
@@ -27,10 +30,9 @@ class NpbApi::PitchingStats
|
|
27
30
|
arr << {
|
28
31
|
date: @date,
|
29
32
|
game_id: @game_id,
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
player_id: player_id(row),
|
33
|
+
order: order,
|
34
|
+
result: result(row),
|
35
|
+
player_id: player_id(row),
|
34
36
|
earned_run_average: row.children[5].text.to_f,
|
35
37
|
innings_pitched: innings_pitched(row),
|
36
38
|
batters_faced: row.children[9].text.to_i,
|
@@ -41,21 +43,22 @@ class NpbApi::PitchingStats
|
|
41
43
|
hit_batsmen_and_bases_on_balls: row.children[19].text.to_i,
|
42
44
|
runs: row.children[21].text.to_i,
|
43
45
|
earned_runs: row.children[23].text.to_i,
|
46
|
+
team_id: team_id(home_or_away),
|
44
47
|
}
|
45
48
|
end
|
46
49
|
end
|
47
50
|
|
48
51
|
def player_id(row)
|
49
52
|
row.children[3].css('a').attribute('href').value =~ /\A\/npb\/player\?id=(\d+)\z/
|
50
|
-
$1
|
53
|
+
$1.to_i
|
51
54
|
end
|
52
55
|
|
53
56
|
def innings_pitched(row)
|
54
57
|
# \xc2\xa0 =>
|
55
58
|
if row.children[7].text =~ /(\d{1,2})\xc2\xa0(\d)\/3\z/
|
56
|
-
$1
|
59
|
+
"#{$1} #{$2}/3"
|
57
60
|
else
|
58
|
-
row.children[7].text
|
61
|
+
row.children[7].text
|
59
62
|
end
|
60
63
|
end
|
61
64
|
|
@@ -73,4 +76,16 @@ class NpbApi::PitchingStats
|
|
73
76
|
nil
|
74
77
|
end
|
75
78
|
end
|
79
|
+
|
80
|
+
def team_id(home_or_away)
|
81
|
+
scoreboard =
|
82
|
+
case home_or_away
|
83
|
+
when :home
|
84
|
+
TableExtraction.new(url: @url, klass: 'scoreboard').doc[1]
|
85
|
+
when :away
|
86
|
+
TableExtraction.new(url: @url, klass: 'scoreboard').doc[0]
|
87
|
+
end
|
88
|
+
scoreboard.css('td.tn').children[0].attribute('href').value =~ /\A\/npb\/teams\/(\d+)\/\z/
|
89
|
+
$1.to_i
|
90
|
+
end
|
76
91
|
end
|
data/lib/npb_api/player.rb
CHANGED