npb 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c93eb2ca7198495ee643bd94544f83623c3edf24
4
+ data.tar.gz: c215b9566154e790d9c0068b69583732e0613aa1
5
+ SHA512:
6
+ metadata.gz: 7b3324409f4c7b36e92bd8c7e1724c7610669ba46521cdcfbad80bf400c26a3f5ac6f219c040dbe6b94367907fae553b7119041d0c0caf51cbb78ea433f83d8e
7
+ data.tar.gz: 818bdd93c6c3f9d6c22a18baefda7e17ac147cdf62340ba34cb54f259a3103636d0fb1b2bc531a9169099d99450ef621ce20c477cfef9e299df13def288e13df
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in npb.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # Npb
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/npb`. 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 'npb'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install npb
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]/npb/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
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "npb"
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
data/bin/setup ADDED
@@ -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,69 @@
1
+ require 'nokogiri'
2
+ require 'open-uri'
3
+ require 'active_support'
4
+ require 'active_support/core_ext'
5
+
6
+ module Npb
7
+ class Schedule
8
+ attr_accessor :home, :visitor, :studium, :start_at
9
+
10
+ class << self
11
+ def all
12
+ first_days_of_week.each_with_object([]) do |first_day_of_week, arr|
13
+ puts "processing #{first_day_of_week}"
14
+ sources(first_day_of_week: first_day_of_week).each do |source|
15
+ next if source.css('td').text.include?('試合はありません')
16
+ @date = source.css('th').text if source.css('th').present?
17
+ @time = source.css('td.pl7')[2].text.split[0]
18
+ arr << new(
19
+ home: source.css('td.pl7')[0].text,
20
+ visitor: source.css('td.pl7')[1].text,
21
+ studium: source.css('td.pl7')[2].text.split[1],
22
+ start_at: Time.new(2015, month, day, hour, minute)
23
+ )
24
+ end
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ def first_days_of_week
31
+ first_day = Date.new(2015, 3, 23)
32
+ last_day = Date.new(2015, 11, 2)
33
+ (first_day..last_day).to_a.select { |day| day.wday == 1 }
34
+ end
35
+
36
+ def sources(first_day_of_week: nil)
37
+ url = "http://baseball.yahoo.co.jp/npb/schedule/?&date=#{first_day_of_week.strftime('%Y%m%d')}"
38
+ Nokogiri::HTML(open(url)).css('.NpbSchedule > table > tr')
39
+ end
40
+
41
+ def month
42
+ @date =~ /\A(\d+)月(\d+)日(.)\z/
43
+ $1.to_i
44
+ end
45
+
46
+ def day
47
+ @date =~ /\A(\d+)月(\d+)日(.)\z/
48
+ $2.to_i
49
+ end
50
+
51
+ def hour
52
+ @time =~ /\A(\d+):(\d+)\z/
53
+ $1.to_i
54
+ end
55
+
56
+ def minute
57
+ @time =~ /\A(\d+):(\d+)\z/
58
+ $2.to_i
59
+ end
60
+ end
61
+
62
+ def initialize(home: nil, visitor: nil, studium: nil, start_at: nil)
63
+ @home = home
64
+ @visitor = visitor
65
+ @studium = studium
66
+ @start_at = start_at
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Npb
2
+ VERSION = "0.1.2"
3
+ end
data/lib/npb.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "npb/version"
2
+ require "npb/schedule"
3
+
4
+ module Npb
5
+ # Your code goes here...
6
+ end
data/npb-0.1.1.gem ADDED
Binary file
data/npb.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'npb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "npb"
8
+ spec.version = Npb::VERSION
9
+ spec.authors = ["ohtsuka"]
10
+ spec.email = ["t.o.0526@gmail.com"]
11
+
12
+ spec.summary = %q{Write a short summary, because Rubygems requires one.}
13
+ spec.description = %q{Write a longer description or delete this line.}
14
+ spec.homepage = "https://github.com/to0526/npb_schedule"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.9"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+
24
+ spec.add_runtime_dependency 'activesupport', '4.2.1'
25
+ spec.add_runtime_dependency 'nokogiri', '1.6.6.2'
26
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: npb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - ohtsuka
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-05-12 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: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 4.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 4.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: nokogiri
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '='
60
+ - !ruby/object:Gem::Version
61
+ version: 1.6.6.2
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '='
67
+ - !ruby/object:Gem::Version
68
+ version: 1.6.6.2
69
+ description: Write a longer description or delete this line.
70
+ email:
71
+ - t.o.0526@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".travis.yml"
78
+ - Gemfile
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/npb.rb
84
+ - lib/npb/schedule.rb
85
+ - lib/npb/version.rb
86
+ - npb-0.1.1.gem
87
+ - npb.gemspec
88
+ homepage: https://github.com/to0526/npb_schedule
89
+ licenses: []
90
+ metadata: {}
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.4.6
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: Write a short summary, because Rubygems requires one.
111
+ test_files: []