npbs 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 67db6c8972961bea9853790abfa32bb6e504711c
4
+ data.tar.gz: 080b33f02bfde05b351c1a57fe2f47d98edbe787
5
+ SHA512:
6
+ metadata.gz: 5716c8d36521e4615adb8d21d7847d3e96e29b749818a1ce0de27d0f75e7b3c48c929dbe804e0f09ad2d7cdd144f9e009e03d85f56fdde55f7a7a9bc3df1aefd
7
+ data.tar.gz: 2b0b836022307c711595c071e5a24c53e43c2d0bb2572807563b327653d1e7852841a32367a54d42554df12f152dcf54ec16ecff8dfaab1a9efd1bb6271c2092
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /vendor
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in npbs.gemspec
4
+ gemspec
5
+
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 山口将平
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # Npbs
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/npbs`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'npbs'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install npbs
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/npbs/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "npbs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,181 @@
1
+ # coding: utf-8
2
+ require "npbs/version"
3
+
4
+ require "open-uri"
5
+ require "date"
6
+
7
+ require "nokogiri"
8
+
9
+ module Npbs
10
+ # Your code goes here...
11
+ class NPB
12
+ attr_reader :base_url, :path
13
+ def initialize
14
+ @base_url = "http://bis.npb.or.jp";
15
+ @path = "";
16
+ # http://bis.npb.or.jpだけを対象にするので、文字コードは決め打ち
17
+ @charset = "Shift-jis"
18
+ end
19
+
20
+ def fetch_doc(ext_path=nil)
21
+ Nokogiri::HTML(fetch_html(ext_path), nil, @charset)
22
+ end
23
+
24
+ def fetch_html(ext_path=nil)
25
+ path = ext_path.nil? ? @path : ext_path
26
+ URI.parse(@base_url + path).read
27
+ end
28
+
29
+ end
30
+
31
+ class Player < NPB
32
+ attr_reader :name, :path, :first_name, :last_name, :first_name_kana, :last_name_kana,
33
+ :number, :birthday, :height, :weight, :high_school, :college, :company
34
+ def initialize(name, path)
35
+ super()
36
+ @name = name
37
+ @path = path
38
+ end
39
+ def fetch
40
+ doc = fetch_doc
41
+ name = @name.split(' ')
42
+ @first_name = name[0]
43
+ @last_name = name[1]
44
+ if @last_name.nil? && doc.css('.registerPlayer h1').inner_text.match('(')
45
+ name = doc.css('.registerPlayer h1').inner_text.match('(.*)').to_s.split(' ')
46
+ if name[1].nil?
47
+ name = doc.css('.registerPlayer h1').inner_text.match('(.*)').to_s.split('・')
48
+ end
49
+ @first_name = name[0].gsub('(','')
50
+ @last_name = name[1].gsub(')','')
51
+ end
52
+
53
+ @number = doc.css('#registerdivtitle .registerNo').inner_text
54
+
55
+ doc.css('#registerdivCareer').each do |prof|
56
+ name_kana = prof.css("tr:first-child td").inner_text.split('・')
57
+ @first_name_kana = name_kana[0]
58
+ @last_name_kana = name_kana[1]
59
+ # 外人対応
60
+ if prof.css("tr:first-child td").inner_text =~ /[A-Z]/
61
+ name_data = prof.css("tr:first-child td").inner_text.split('(')
62
+ real_name = name_data[0].split('・')
63
+ @first_name = real_name[0]
64
+ @last_name = real_name[1]
65
+ kana = name_data[1].nil? ? name_data[0].split(/\s/) : name_data[1].split(/\s/)
66
+ @first_name_kana = kana[0].gsub(/(/,'')
67
+ @last_name_kana = kana[1..-1].join(' ').gsub(/)/,'')
68
+ if @first_name.nil? || @last_name.nil?
69
+ @first_name = @first_name_kana
70
+ @last_name = @last_name_kana
71
+ end
72
+ end
73
+ @first_name = @first_name.gsub(/(\s| )/,' ').gsub(/^.*(/,'')
74
+ @last_name = @last_name.gsub(/(\s| )/,' ').gsub(/)/,'')
75
+ @first_name_kana = @first_name_kana.gsub(/(\s| )/,' ').gsub(/^.*(/,'')
76
+ @last_name_kana = @last_name_kana.gsub(/(\s| )/,' ').gsub(/)/,'')
77
+ data = prof.css('tr:nth-child(2) td').inner_text.split(' ')
78
+ data.delete('')
79
+ @birthday = Date.strptime(data[0],'%Y年%m月%d日生')
80
+ @height = data[1].match(/[0-9]{3,}/).to_s
81
+ @weight = data[2].match(/[0-9]{2,3}/).to_s
82
+ history = prof.css('tr:nth-child(3) td').inner_text.split(' - ')
83
+ history.delete('')
84
+ @high_school = history[0]
85
+ if history.length == 2 && /大$/ === history[1] then
86
+ @college = history[1]
87
+ elsif history.length == 2 then
88
+ @company = history[1]
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ class TeamsPlayers < NPB
95
+ attr_reader :teams
96
+ def initialize
97
+ super
98
+ @path = "/players/"
99
+ @teams = []
100
+ end
101
+ def fetch
102
+ fetch_doc.css(".playerTeamsub").each do |node|
103
+ node.css("tr:not(:first-child)").each do |team|
104
+ name = team.css('a').inner_text
105
+ path = team.css('a').first.attributes.first[1].value
106
+ @teams << TeamPlayers.new(name, path)
107
+ end
108
+ end
109
+ @teams
110
+ end
111
+ end
112
+
113
+ class TeamPlayers < NPB
114
+ attr_reader :name, :path, :players
115
+ def initialize(name, path)
116
+ super()
117
+ @name = name
118
+ @path = path
119
+ @players = []
120
+ end
121
+ def fetch
122
+ fetch_doc.css('.rosterPlayer').each do |node|
123
+ node.css('a').each do |p|
124
+ name = p.inner_text.gsub(/ /,' ')
125
+ next if name =~ /※/
126
+ path = p.attributes.first[1].value
127
+ @players << Player.new(name,path)
128
+ end
129
+ end
130
+ @players
131
+ end
132
+ end
133
+
134
+ class Matches < NPB
135
+ def initialize
136
+ super
137
+ @path = "/#{Date.today.year}/games/"
138
+ end
139
+ def today
140
+ result = []
141
+ fetch_doc.css(".contentsgame").each do |node|
142
+ node.css("tr:nth-child(odd)").each do |game|
143
+
144
+ h_team = game.css("td:nth-child(2)").inner_text.gsub(/(\s| )+/, '')
145
+ h_score = game.css("td:nth-child(3)").inner_text.gsub(/(\s| )+/, '')
146
+
147
+ v_score = game.css("td:nth-child(5)").inner_text.gsub(/(\s| )+/, '')
148
+ v_team = game.css("td:nth-child(6)").inner_text.gsub(/(\s| )+/,'')
149
+
150
+ result << Match.new(TeamResult.new(h_team, h_score),
151
+ TeamResult.new(v_team, v_score))
152
+ end
153
+ end
154
+ result
155
+ end
156
+ end
157
+
158
+ class Match
159
+ attr_reader :home_team, :visitor_team
160
+ def initialize(home, visitor)
161
+ @home = home
162
+ @visitor = visitor
163
+ end
164
+ def winner
165
+ winner = [@home, @visitor].max_by{ |team| team.score}
166
+ winner.name
167
+ end
168
+ def losseer
169
+ losser = [@home, @visitor].min_by{ |team| team.score}
170
+ losser.name
171
+ end
172
+ end
173
+
174
+ class TeamResult
175
+ attr_reader :name, :score
176
+ def initialize(name, score)
177
+ @name = name
178
+ @score = score
179
+ end
180
+ end
181
+ end
@@ -0,0 +1,3 @@
1
+ module Npbs
2
+ VERSION = "0.1.10"
3
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'npbs/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "npbs"
8
+ spec.version = Npbs::VERSION
9
+ spec.authors = ["shouhei yamaguchi"]
10
+ spec.email = ["shouhei.yamaguchi.ssi@gmail.com"]
11
+
12
+ spec.summary = %q{This gem scrapes "http://bis.npb.or.jp".}
13
+ spec.description = %q{If you needs npb's data. Please use this gem. }
14
+ spec.homepage = "https://github.com/shouhei/npbs"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.9"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec"
33
+ spec.add_dependency "nokogiri"
34
+ end
metadata ADDED
@@ -0,0 +1,114 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: npbs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.10
5
+ platform: ruby
6
+ authors:
7
+ - shouhei yamaguchi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: 'If you needs npb''s data. Please use this gem. '
70
+ email:
71
+ - shouhei.yamaguchi.ssi@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - lib/npbs.rb
87
+ - lib/npbs/version.rb
88
+ - npbs.gemspec
89
+ homepage: https://github.com/shouhei/npbs
90
+ licenses:
91
+ - MIT
92
+ metadata:
93
+ allowed_push_host: https://rubygems.org
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.4.5
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: This gem scrapes "http://bis.npb.or.jp".
114
+ test_files: []