npb_result 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +10 -12
- data/exe/npb_result +1 -1
- data/lib/npb_result.rb +2 -45
- data/lib/npb_result/game.rb +18 -0
- data/lib/npb_result/results.rb +90 -0
- data/lib/npb_result/version.rb +1 -1
- data/npb_result.gemspec +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1530d536059ab2d6c788a1de303d83fbe74ec2d3979a004d8679fdd47ac5f18b
|
4
|
+
data.tar.gz: 403224fc1ba64e4b4614c6da6436c7c801d82662194ab53f28358474e798ca26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16113a89aa9607f8e73b6f147e0f2e725678f6dcbb3ca69757b44a044ea68aa64144828055365cea6ff7e629d15042c4347af83e97857f7d73af8da44c746679
|
7
|
+
data.tar.gz: 8153c08571c3f9065d3c0cd27d4d46819f93e5817e464995bea88e4d5d2079c650bbd1f366acdc55ddb115cf0c71a900f85007cec3ee34e89711ceb64651956f
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# NpbResult
|
2
2
|
|
3
|
-
|
3
|
+
get NPB game result
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -33,17 +33,15 @@ $ npb_result
|
|
33
33
|
or
|
34
34
|
|
35
35
|
```
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
NpbResult.list(date: Date.today, team: "オリックス")
|
46
|
-
#=> [{:home_team=>"オリックス", :home_score=>1, :away_team=>"日本ハム", :away_score=>3, :status=>"結果"}]
|
36
|
+
date = Date.new(2019, 4, 7)
|
37
|
+
NpbResult::Results.new(date: date).select_team("オリックス")
|
38
|
+
#=> #<NpbResult::Game:0x00007f9bf498bec0
|
39
|
+
@away_team="楽天",
|
40
|
+
@away_score=5,
|
41
|
+
@home_team="オリックス",
|
42
|
+
@home_score=5,
|
43
|
+
@status="結果",
|
44
|
+
@start_time=2019-04-07 13:00:00 +0900>
|
47
45
|
```
|
48
46
|
|
49
47
|
|
data/exe/npb_result
CHANGED
data/lib/npb_result.rb
CHANGED
@@ -1,49 +1,6 @@
|
|
1
1
|
require "npb_result/version"
|
2
|
+
require "npb_result/results"
|
3
|
+
require "npb_result/game"
|
2
4
|
require "date"
|
3
5
|
require "open-uri"
|
4
6
|
require "nokogiri"
|
5
|
-
|
6
|
-
module NpbResult
|
7
|
-
def self.display(date: Date.today, team: nil)
|
8
|
-
results = list(date: date, team: team)
|
9
|
-
if results.empty?
|
10
|
-
"試合なし"
|
11
|
-
else
|
12
|
-
results.inject("") do |display, result|
|
13
|
-
display << "【#{result[:status]}】#{result[:away_team]} (#{result[:away_score]})" +
|
14
|
-
" - (#{result[:home_score]}) #{result[:home_team]}\n"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.list(date: Date.today, team: nil)
|
20
|
-
d = date
|
21
|
-
input_url = "https://baseball.yahoo.co.jp/npb/schedule/?date=#{d.strftime("%Y")}#{d.strftime("%m")}#{d.strftime("%d")}"
|
22
|
-
doc = Nokogiri::HTML.parse(open(input_url).read)
|
23
|
-
|
24
|
-
teams = doc.css(".yjMS.bb").map { |e| e.text }
|
25
|
-
scores = doc.css(".score_r").map { |e| e.text.to_i }
|
26
|
-
status = doc.css("td.yjMSt").map { |e| e.text }
|
27
|
-
|
28
|
-
result_list = []
|
29
|
-
|
30
|
-
status.size.times.with_index do |i|
|
31
|
-
result_list << { home_team: teams[i * 2],
|
32
|
-
home_score: scores[i * 2],
|
33
|
-
away_team: teams[i * 2 + 1],
|
34
|
-
away_score: scores[i * 2 + 1],
|
35
|
-
status: status[i] }
|
36
|
-
end
|
37
|
-
select_team(result_list, team)
|
38
|
-
end
|
39
|
-
|
40
|
-
private
|
41
|
-
|
42
|
-
def self.select_team(all_result, team)
|
43
|
-
if team
|
44
|
-
team_result = all_result.select { |game| game[:home_team] == team || game[:away_team] == team }
|
45
|
-
else
|
46
|
-
all_result
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module NpbResult
|
2
|
+
class Game
|
3
|
+
attr_reader :away_team, :away_score, :home_team, :home_score, :status, :start_time
|
4
|
+
|
5
|
+
def initialize(away_team, away_score, home_team, home_score, status, start_time)
|
6
|
+
@away_team = away_team
|
7
|
+
@away_score = away_score
|
8
|
+
@home_team = home_team
|
9
|
+
@home_score = home_score
|
10
|
+
@status = status
|
11
|
+
@start_time = start_time
|
12
|
+
end
|
13
|
+
|
14
|
+
def display
|
15
|
+
"【#{status}】#{away_team} (#{away_score}) - (#{home_score}) #{home_team}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
module NpbResult
|
2
|
+
class Results
|
3
|
+
attr_reader :size
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(date: Date.today)
|
7
|
+
@date = date
|
8
|
+
|
9
|
+
doc = read_url(date)
|
10
|
+
away_team = away_team(doc)
|
11
|
+
away_score = away_score(doc)
|
12
|
+
home_team = home_team(doc)
|
13
|
+
home_score = home_score(doc)
|
14
|
+
status = status(doc)
|
15
|
+
start_time = start_time(doc)
|
16
|
+
|
17
|
+
@size = status.size
|
18
|
+
@results = []
|
19
|
+
|
20
|
+
@size.times do |i|
|
21
|
+
@results << Game.new(
|
22
|
+
away_team[i], away_score[i],
|
23
|
+
home_team[i], home_score[i],
|
24
|
+
status[i], start_time[i]
|
25
|
+
)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def select_team(team)
|
30
|
+
selected_team = @results.select { |game| game.home_team == team || game.away_team == team }
|
31
|
+
selected_team ? selected_team[0] : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def display
|
35
|
+
if @results.empty?
|
36
|
+
"試合なし"
|
37
|
+
else
|
38
|
+
inject("") do |display, result|
|
39
|
+
display << "【#{result.status}】#{result.away_team} (#{result.away_score})" \
|
40
|
+
" - (#{result.home_score}) #{result.home_team}\n"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def each
|
46
|
+
@results.each { |result| yield(result) }
|
47
|
+
end
|
48
|
+
|
49
|
+
def [](idx)
|
50
|
+
@results[idx]
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def read_url(date)
|
56
|
+
d = date
|
57
|
+
input_url = "https://baseball.yahoo.co.jp/npb/schedule/?date=" \
|
58
|
+
"#{d.strftime("%Y")}#{d.strftime("%m")}#{d.strftime("%d")}"
|
59
|
+
Nokogiri::HTML.parse(open(input_url).read)
|
60
|
+
end
|
61
|
+
|
62
|
+
def away_team(doc)
|
63
|
+
doc.css(".yjMS.bb").map(&:text).select.with_index { |_, i| i.even? }
|
64
|
+
end
|
65
|
+
|
66
|
+
def home_team(doc)
|
67
|
+
doc.css(".yjMS.bb").map(&:text).select.with_index { |_, i| i.odd? }
|
68
|
+
end
|
69
|
+
|
70
|
+
def away_score(doc)
|
71
|
+
doc.css(".score_r").map(&:text).map(&:to_i).select.with_index { |_, i| i.even? }
|
72
|
+
end
|
73
|
+
|
74
|
+
def home_score(doc)
|
75
|
+
doc.css(".score_r").map(&:text).map(&:to_i).select.with_index { |_, i| i.odd? }
|
76
|
+
end
|
77
|
+
|
78
|
+
def status(doc)
|
79
|
+
doc.css("td.yjMSt").map(&:text)
|
80
|
+
end
|
81
|
+
|
82
|
+
def start_time(doc)
|
83
|
+
times = doc.css("td.yjSt.bl em").map(&:text).map { |e| e.split(":") }
|
84
|
+
d = @date
|
85
|
+
times.map do |time|
|
86
|
+
Time.new(d.strftime("%Y"), d.strftime("%m"), d.strftime("%d"), time[0], time[1])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/npb_result/version.rb
CHANGED
data/npb_result.gemspec
CHANGED
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
|
|
23
23
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
24
24
|
spec.require_paths = ["lib"]
|
25
25
|
|
26
|
-
spec.add_development_dependency "bundler", "~>
|
26
|
+
spec.add_development_dependency "bundler", "~> 2"
|
27
27
|
spec.add_development_dependency "rake", "~> 10.0"
|
28
28
|
spec.add_development_dependency "rspec", "~> 3.0"
|
29
29
|
spec.add_development_dependency "irb", "~> 1.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: npb_result
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kasumi8pon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -101,6 +101,8 @@ files:
|
|
101
101
|
- bin/setup
|
102
102
|
- exe/npb_result
|
103
103
|
- lib/npb_result.rb
|
104
|
+
- lib/npb_result/game.rb
|
105
|
+
- lib/npb_result/results.rb
|
104
106
|
- lib/npb_result/version.rb
|
105
107
|
- npb_result.gemspec
|
106
108
|
homepage: https://github.com/kasumi8pon
|