npb_headline 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -0
- data/.rspec +2 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +44 -0
- data/Rakefile +6 -0
- data/bin/npb_headline +5 -0
- data/lib/npb_headline.rb +7 -0
- data/lib/npb_headline/base.rb +47 -0
- data/lib/npb_headline/command.rb +17 -0
- data/lib/npb_headline/parameters.rb +28 -0
- data/lib/npb_headline/version.rb +3 -0
- data/npb_headline.gemspec +27 -0
- data/spec/npb_headline_spec.rb +25 -0
- data/spec/spec_helper.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 713e453c3da92b623c5c50bc5db70b446a1ca27e
|
4
|
+
data.tar.gz: 1843e5b842c1431e625018818546870ade9e630c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 4e76ed4ba6a697ce3b5f787d0b681f54e4343400ce2920ee9107cf2d497b7916d8967f072c8eef7e06d6f5160d4afbfb3cfb4644e671584ec55aa8cc0514905e
|
7
|
+
data.tar.gz: 6fdc242cbba9cbcad9c41fa643c4b7ef374d3bd8d28bcc2a6e2be6502eee48dde4930c84244f49a30732218435e08447ad230111053a98369754814497394c8b
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 kami
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# NpbHeadline
|
2
|
+
|
3
|
+
NpbHeadline shows the headlines of NPB (Nihon Professional Baseball) based on Y's Sports on command line.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
To begin with, install gem:
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install npb_headline
|
11
|
+
```
|
12
|
+
|
13
|
+
To show the headlines, execute `npb_headline` command with `team_name` option:
|
14
|
+
|
15
|
+
```
|
16
|
+
$ npb_headline {team_name}
|
17
|
+
```
|
18
|
+
|
19
|
+
The available values of `team_name` are as follows:
|
20
|
+
|
21
|
+
- giants
|
22
|
+
- swallows
|
23
|
+
- baystars
|
24
|
+
- dragons
|
25
|
+
- tigers
|
26
|
+
- carp
|
27
|
+
- lions
|
28
|
+
- fighters
|
29
|
+
- marines
|
30
|
+
- orix
|
31
|
+
- hawks
|
32
|
+
- eagles
|
33
|
+
|
34
|
+
## Demo
|
35
|
+
|
36
|
+
![](docs/demo.gif)
|
37
|
+
|
38
|
+
## Contributing
|
39
|
+
|
40
|
+
1. Fork it ( https://github.com/kami30k/npb_headline/fork )
|
41
|
+
2. Create your feature branch (git checkout -b my-new-feature)
|
42
|
+
3. Commit your changes (git commit -am 'Add some feature')
|
43
|
+
4. Push to the branch (git push origin my-new-feature)
|
44
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/npb_headline
ADDED
data/lib/npb_headline.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
require 'nokogiri'
|
3
|
+
|
4
|
+
module NpbHeadline
|
5
|
+
class Base
|
6
|
+
SIZE = 10
|
7
|
+
|
8
|
+
SOURCE = 'http://baseball.yahoo.co.jp/npb/headlines/?team=%d'
|
9
|
+
|
10
|
+
def initialize(team_id)
|
11
|
+
@team_id = team_id
|
12
|
+
end
|
13
|
+
|
14
|
+
def articles
|
15
|
+
_articles = []
|
16
|
+
|
17
|
+
doc.css('#NpbNewsSearch li').each do |li|
|
18
|
+
article = {}
|
19
|
+
|
20
|
+
li.css('a').each do |a|
|
21
|
+
article[:link] = a.attribute('href').value
|
22
|
+
article[:title] = a.content
|
23
|
+
end
|
24
|
+
|
25
|
+
li.css('em').each do |em|
|
26
|
+
m = em.content.match /^((?<publisher>.+))\s(?<date>.+)$/
|
27
|
+
article[:publisher] = m[:publisher]
|
28
|
+
article[:date] = m[:date]
|
29
|
+
end
|
30
|
+
|
31
|
+
_articles << article
|
32
|
+
end
|
33
|
+
|
34
|
+
_articles.shift(SIZE)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def doc
|
40
|
+
Nokogiri::HTML(open(url))
|
41
|
+
end
|
42
|
+
|
43
|
+
def url
|
44
|
+
sprintf(SOURCE, @team_id)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module NpbHeadline
|
2
|
+
class Command
|
3
|
+
class << self
|
4
|
+
def start
|
5
|
+
params = NpbHeadline::Parameters.new(ARGV)
|
6
|
+
|
7
|
+
headline = NpbHeadline::Base.new(params.team_id)
|
8
|
+
headline.articles.each do |h|
|
9
|
+
puts "#{h[:title]}(#{h[:publisher]})"
|
10
|
+
puts h[:date]
|
11
|
+
puts h[:link]
|
12
|
+
puts
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module NpbHeadline
|
2
|
+
class Parameters
|
3
|
+
TEAMS = {
|
4
|
+
'giants' => 1,
|
5
|
+
'swallows' => 2,
|
6
|
+
'baystars' => 3,
|
7
|
+
'dragons' => 4,
|
8
|
+
'tigers' => 5,
|
9
|
+
'carp' => 6,
|
10
|
+
'lions' => 7,
|
11
|
+
'fighters' => 8,
|
12
|
+
'marines' => 9,
|
13
|
+
'orix' => 11,
|
14
|
+
'hawks' => 12,
|
15
|
+
'eagles' => 376
|
16
|
+
}
|
17
|
+
|
18
|
+
attr_reader :team_id
|
19
|
+
|
20
|
+
def initialize(argv)
|
21
|
+
team_name = argv[0]
|
22
|
+
|
23
|
+
raise ArgumentError unless TEAMS.has_key?(team_name)
|
24
|
+
|
25
|
+
@team_id = TEAMS[team_name]
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'npb_headline/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'npb_headline'
|
9
|
+
spec.version = NpbHeadline::VERSION
|
10
|
+
spec.authors = ['kami']
|
11
|
+
spec.email = ['kami30k@gmail.com']
|
12
|
+
spec.summary = %q{NpbHeadline show the headlines of NPB (Nihon Professional Baseball) based on Y's Sports on command line.}
|
13
|
+
spec.description = %q{NpbHeadline show the headlines of NPB (Nihon Professional Baseball) based on Y's Sports on command line.}
|
14
|
+
spec.homepage = ''
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0")
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'nokogiri'
|
23
|
+
|
24
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
25
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
26
|
+
spec.add_development_dependency 'rspec'
|
27
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NpbHeadline do
|
4
|
+
describe NpbHeadline::Parameters do
|
5
|
+
let(:params) { NpbHeadline::Parameters.new(['carp']) }
|
6
|
+
|
7
|
+
it 'should return equivalent id' do
|
8
|
+
expect(params.team_id).to eq 6
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe NpbHeadline::Base do
|
13
|
+
describe '#articles' do
|
14
|
+
let(:articles) { NpbHeadline::Base.new(6).articles }
|
15
|
+
|
16
|
+
it 'should return correct size' do
|
17
|
+
expect(articles.size).to eq 10
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should include correct link' do
|
21
|
+
expect(articles[0][:link]).to match /^http:\/\/headlines\.yahoo\.co\.jp\/hl\?a=.*$/
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: npb_headline
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- kami
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-01-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: NpbHeadline show the headlines of NPB (Nihon Professional Baseball) based
|
70
|
+
on Y's Sports on command line.
|
71
|
+
email:
|
72
|
+
- kami30k@gmail.com
|
73
|
+
executables:
|
74
|
+
- npb_headline
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- ".gitignore"
|
79
|
+
- ".rspec"
|
80
|
+
- Gemfile
|
81
|
+
- LICENSE.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- bin/npb_headline
|
85
|
+
- lib/npb_headline.rb
|
86
|
+
- lib/npb_headline/base.rb
|
87
|
+
- lib/npb_headline/command.rb
|
88
|
+
- lib/npb_headline/parameters.rb
|
89
|
+
- lib/npb_headline/version.rb
|
90
|
+
- npb_headline.gemspec
|
91
|
+
- spec/npb_headline_spec.rb
|
92
|
+
- spec/spec_helper.rb
|
93
|
+
homepage: ''
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.2
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: NpbHeadline show the headlines of NPB (Nihon Professional Baseball) based
|
117
|
+
on Y's Sports on command line.
|
118
|
+
test_files:
|
119
|
+
- spec/npb_headline_spec.rb
|
120
|
+
- spec/spec_helper.rb
|