ruboty-train_delay 0.1.0

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: e30494f3115231f9ffaae6e4633d4dbc81c9b40c
4
+ data.tar.gz: a39062bab880d8442d36b9b03c2ec013c571a4e7
5
+ SHA512:
6
+ metadata.gz: 9260d605cec3070d610851816b22ef2fcf0d9685ac39f9ad6d025f1e509089407c4aa8004045583d82e490059ca9366b920c3c0a6e3330fe59a1a062c0116258
7
+ data.tar.gz: d582c4726b0e1ec125fcb04ee14be331d794fd606d611106827538ea518fe441f6be3729bd08ac878c0d74705d735239a0a64653533094a76f598f31ace1033f
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.1
@@ -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,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-train_delay.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 akira.takahashi
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.
data/README.md ADDED
@@ -0,0 +1,52 @@
1
+ # Ruboty::TrainDelay
2
+
3
+ check train status by [Yahoo!路線情報](http://transit.yahoo.co.jp/traininfo/top)
4
+
5
+ hubot-script-verison: https://gist.github.com/rike422/0041ab1fdde2298f5094
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ruboty-train_delay'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ruboty-train_delay
21
+
22
+ ## Usage
23
+
24
+ ```
25
+ > @ruboty delay 山手線
26
+ 山手線: 現在、事故・遅延に関する情報はありません。
27
+ > @ruboty delay 小湊鉄道線
28
+ 小湊鉄道線: 関東・東北豪雨の影響で、本日も月崎~上総中野駅間の運転を見合わせています。なお、バス代行輸送を行っています。
29
+ > @ruboty delay 中央
30
+ 絞り込めませんね。下のどれかでしょうか?
31
+ * 中央線(快速)[東京~高尾]
32
+ * 中央総武線(各停)
33
+ * 中央本線[高尾~大月]}
34
+ > @ruboty delay JR神戸線 of 近畿
35
+ JR神戸線: 18:51頃、尼崎~立花駅間で発生した人身事故の影響で、現在も列車に遅れや運休が出ています。
36
+ > @ruboty 副都心線遅れてる?
37
+ 東京メトロ副都心線: 現在、事故・遅延に関する情報はありません。
38
+ ```
39
+
40
+ ## Development
41
+
42
+ 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.
43
+
44
+ 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).
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/[my-github-username]/ruboty-train_delay/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/train_delay"
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,26 @@
1
+ require "ruboty/train_delay/actions/delay"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class TrainDelay < Base
6
+ on(/delay (?<route>[^\s]+)?\z/,
7
+ name: 'delay',
8
+ description: ''
9
+ )
10
+
11
+ on(/delay (?<route>.+) of (?<area>[^\s]+)?\z/,
12
+ name: 'delay',
13
+ description: ''
14
+ )
15
+
16
+ on(/(?<route>.+)線遅れてる(\?|?)\z/,
17
+ name: 'delay',
18
+ description: ''
19
+ )
20
+
21
+ def delay(message)
22
+ Ruboty::TrainDelay::Actions::Delay.new(message).call
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,77 @@
1
+ require "nokogiri"
2
+ require "open-uri"
3
+
4
+ module Ruboty
5
+ module TrainDelay
6
+ AREA_SET = {
7
+ "北海道": 2,
8
+ "東北": 3,
9
+ "関東": 4,
10
+ "中部": 5,
11
+ "近畿": 6,
12
+ "九州": 7,
13
+ "中国": 8,
14
+ "四国": 9
15
+ }
16
+
17
+ module Actions
18
+ class Delay < Ruboty::Actions::Base
19
+ def call
20
+ list = delay_list
21
+ return message.reply(found_route) if list.length == 0
22
+ return message.reply(many_route(list)) if list.length > 1
23
+ message.reply("#{list.first[:name]}: #{cause_delay(list.first)}")
24
+ rescue OpenURI::HTTPError => e
25
+ message.reply("情報を取得することができませんでした。URLが正しいか確認してください。")
26
+ message.reply("今回使用したURL:#{list_url}")
27
+ end
28
+
29
+ private
30
+
31
+ def area
32
+ return "関東" unless message.match_data.names.include? "area"
33
+ message[:area]
34
+ end
35
+
36
+ def route
37
+ message[:route]
38
+ end
39
+
40
+ def area_code
41
+ Ruboty::TrainDelay::AREA_SET[area.to_sym]
42
+ end
43
+
44
+ def cause_delay(route)
45
+ Nokogiri::HTML(open(route[:href]))
46
+ .css('#mdServiceStatus p').text
47
+ end
48
+
49
+ def delay_list
50
+ doc = Nokogiri::HTML(open(list_url))
51
+ .css("#mdAreaMajorLine .elmTblLstLine > table tr a")
52
+ .map { |a| { name: a.content, href: a.attributes["href"].value } }
53
+ .select { |site| site[:name].include? route }
54
+ end
55
+
56
+ def found_route
57
+ <<-"EOS"
58
+ 知らない路線です。
59
+ #{list_url}
60
+ から探してください。
61
+ EOS
62
+ end
63
+
64
+ def list_url
65
+ "http://transit.loco.yahoo.co.jp/traininfo/area/#{area_code}/"
66
+ end
67
+
68
+ def many_route(routes)
69
+ <<-"EOS"
70
+ 絞り込めませんね。下のどれかでしょうか?
71
+ #{routes.map { |route| " * #{route[:name]}" }.join("\n") }}
72
+ EOS
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module TrainDelay
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require "ruboty/train_delay/version"
2
+ require "ruboty/handlers/train_delay"
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/train_delay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-train_delay"
8
+ spec.version = Ruboty::TrainDelay::VERSION
9
+ spec.authors = ["akira.takahashi"]
10
+ spec.email = ["rike422@gmail.com"]
11
+ spec.summary = %q{check train status}
12
+ spec.description = %q{check train status}
13
+ spec.homepage = "https://github.com/rike422/ruboty-train_delay"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency "ruboty"
22
+ spec.add_runtime_dependency "nokogiri", '~> 1.6.6'
23
+ spec.add_development_dependency "bundler", "~> 1.8"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ end
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe Ruboty::TrainDelay do
4
+ it 'has a version number' do
5
+ expect(Ruboty::TrainDelay::VERSION).not_to be nil
6
+ end
7
+
8
+ it 'does something useful' do
9
+ expect(false).to eq(true)
10
+ end
11
+ end
@@ -0,0 +1,2 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+ require 'ruboty/train_delay'
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-train_delay
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - akira.takahashi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-10-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruboty
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: nokogiri
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.6.6
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.6.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ description: check train status
70
+ email:
71
+ - rike422@gmail.com
72
+ executables:
73
+ - console
74
+ - setup
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".travis.yml"
81
+ - CODE_OF_CONDUCT.md
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/console
87
+ - bin/setup
88
+ - lib/ruboty/handlers/train_delay.rb
89
+ - lib/ruboty/train_delay.rb
90
+ - lib/ruboty/train_delay/actions/delay.rb
91
+ - lib/ruboty/train_delay/version.rb
92
+ - ruboty-train_delay.gemspec
93
+ - spec/ruboty/train_delay_spec.rb
94
+ - spec/spec_helper.rb
95
+ homepage: https://github.com/rike422/ruboty-train_delay
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.4.8
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: check train status
119
+ test_files:
120
+ - spec/ruboty/train_delay_spec.rb
121
+ - spec/spec_helper.rb