npb_api 0.3.0 → 0.3.1
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 +46 -37
- data/lib/npb_api.rb +1 -0
- 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: ae80da680bd018222f39c1e9bf838304cb576c06
|
4
|
+
data.tar.gz: 68e691c98c6bec6be81eb027db5809a111118e79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 653f98a9a30ee58ce690ece84176104bf891da4f40a115d55e3f403631e031391449d7a67aae745c16cd99bad5a0c26ca746469a9ca05f9f9364f1f4692ce192
|
7
|
+
data.tar.gz: cfed9a76fdb4c9a57bfb2284bbcb1938458f3ae6eafde9be7e1b6f226771350a9cc8d5d95667390b3022a879528fd6ace049a2c42bcefaf14e1a871f8fded62e
|
data/lib/npb_api/game.rb
CHANGED
@@ -1,72 +1,71 @@
|
|
1
1
|
class NpbApi::Game
|
2
2
|
def initialize(date: '', id: '')
|
3
3
|
@date = date
|
4
|
-
@id = date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id
|
4
|
+
@id = (date.year.to_s + format('%02d', date.month) + format('%02d', date.day) + id).to_i
|
5
5
|
@doc = Nokogiri::HTML(open("http://baseball.yahoo.co.jp/npb/game/#{@id}/top"))
|
6
6
|
end
|
7
7
|
|
8
8
|
def away
|
9
|
-
|
10
|
-
id: @id.to_i,
|
11
|
-
status: status,
|
12
|
-
team: @doc.css('.column-right.clearfix i').text,
|
13
|
-
score: away_score,
|
14
|
-
result: away_result,
|
15
|
-
datetime: datetime,
|
16
|
-
ballpark: ballpark
|
17
|
-
}
|
9
|
+
info(:away)
|
18
10
|
end
|
19
11
|
|
20
12
|
def home
|
13
|
+
info(:home)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def info(home_or_away)
|
21
19
|
{
|
22
|
-
id: @id
|
20
|
+
id: @id,
|
23
21
|
status: status,
|
24
|
-
|
25
|
-
score:
|
26
|
-
result:
|
22
|
+
team_id: team_id(home_or_away),
|
23
|
+
score: score(home_or_away),
|
24
|
+
result: result(home_or_away),
|
27
25
|
datetime: datetime,
|
28
26
|
ballpark: ballpark
|
29
27
|
}
|
30
28
|
end
|
31
29
|
|
32
|
-
private
|
33
|
-
|
34
30
|
def status
|
35
31
|
@doc.css('.column-center em').text
|
36
32
|
end
|
37
33
|
|
38
|
-
def
|
34
|
+
def score(home_or_away)
|
39
35
|
return nil if status == '試合前中止'
|
40
|
-
|
36
|
+
|
37
|
+
case home_or_away
|
38
|
+
when :away then @doc.css('tr#tb1 td.sum').text.to_i
|
39
|
+
when :home then @doc.css('tr#tb2 td.sum').text.to_i
|
40
|
+
end
|
41
41
|
end
|
42
42
|
|
43
|
-
def
|
43
|
+
def result(home_or_away)
|
44
44
|
return 'postponed' if status.include?('中止')
|
45
45
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
case home_or_away
|
47
|
+
when :away
|
48
|
+
if score(:away) > score(:home)
|
49
|
+
'win'
|
50
|
+
elsif score(:away) < score(:home)
|
51
|
+
'lose'
|
52
|
+
else
|
53
|
+
'draw'
|
54
|
+
end
|
55
|
+
when :home
|
56
|
+
if score(:home) > score(:away)
|
57
|
+
'win'
|
58
|
+
elsif score(:home) < score(:away)
|
59
|
+
'lose'
|
60
|
+
else
|
61
|
+
'draw'
|
62
|
+
end
|
52
63
|
end
|
53
64
|
end
|
54
65
|
|
55
|
-
def home_score
|
56
|
-
return nil if status == '試合前中止'
|
57
|
-
@doc.css('tr#tb2 td.sum').text.to_i
|
58
|
-
end
|
59
|
-
|
60
66
|
def home_result
|
61
67
|
return 'postponed' if status.include?('中止')
|
62
68
|
|
63
|
-
if home_score > away_score
|
64
|
-
'win'
|
65
|
-
elsif home_score < away_score
|
66
|
-
'lose'
|
67
|
-
else
|
68
|
-
'draw'
|
69
|
-
end
|
70
69
|
end
|
71
70
|
|
72
71
|
def datetime
|
@@ -77,4 +76,14 @@ class NpbApi::Game
|
|
77
76
|
def ballpark
|
78
77
|
@doc.css('p.stadium').children[0].text.strip
|
79
78
|
end
|
79
|
+
|
80
|
+
def team_id(home_or_away)
|
81
|
+
anchor =
|
82
|
+
case home_or_away
|
83
|
+
when :home then @doc.css('.column-left.clearfix a')
|
84
|
+
when :away then @doc.css('.column-right.clearfix a')
|
85
|
+
end
|
86
|
+
anchor.attribute('href').value =~ /\A\/npb\/teams\/(\d+)\/\z/
|
87
|
+
$1.to_i
|
88
|
+
end
|
80
89
|
end
|
data/lib/npb_api.rb
CHANGED