ruboty-train_delay 0.1.1 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb77ed7cb5f5d6e8c357ddb095784282fd09bb1e
4
- data.tar.gz: 25bf122448407bcbf2b39d5402539b050420fb7d
3
+ metadata.gz: 9b3a953ac6c8245342fbddb69208cf83b351b93a
4
+ data.tar.gz: 774b49dde7c1041cdb4512f137f26a4f247bd4aa
5
5
  SHA512:
6
- metadata.gz: 14d08bbbf621e157b5d4848a06376206812b8807a87b3191168994408e8013646a5c8d851f3f24ff8d5cfd44ff69ce1c9373ca0c213d6402f54a071ccbd10cc2
7
- data.tar.gz: 89440084626ac42e2d29dd54c21c514282ac421b9b7f6bf76336ac79cba8d5b113d353ba98dd1bbd601e5af1ba8a2134ffb65d5f0bc52d916ee90c8a0fc703d4
6
+ metadata.gz: 415fa7ac6d28a4e4410530df83a06fc85d5459498f4b2cc2b4daf76c5828073157b8f2f562b42eb6c925f984a11dd032374a5917fc96ac88a51873b43a48ba12
7
+ data.tar.gz: c2e23f727b15477c7c73bd59a50fd3b11dfb1729641a6f4cdb00bbd010b71f732a354c88d98ae0eadaf95bb6fdb753bae84407388099ff7d0933865bbb0f29a9
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
  * 中央線(快速)[東京~高尾]
32
32
  * 中央総武線(各停)
33
33
  * 中央本線[高尾~大月]
34
- > @ruboty delay JR神戸線 of 近畿
34
+ > @ruboty delay JR神戸線
35
35
  JR神戸線: 18:51頃、尼崎~立花駅間で発生した人身事故の影響で、現在も列車に遅れや運休が出ています。
36
36
  > @ruboty 副都心線遅れてる?
37
37
  東京メトロ副都心線: 現在、事故・遅延に関する情報はありません。
@@ -16,6 +16,27 @@ module Ruboty
16
16
 
17
17
  module Actions
18
18
  class Delay < Ruboty::Actions::Base
19
+ class << self
20
+ def train_list
21
+ @train_list ||= []
22
+ end
23
+
24
+ def create_train_list
25
+ Ruboty::TrainDelay::AREA_SET.values.each do |area|
26
+ Nokogiri::HTML(open(list_url(area)))
27
+ .css("#mdAreaMajorLine .elmTblLstLine > table tr a")
28
+ .map do |a|
29
+ data = { name: a.content, href: a.attributes["href"].value }
30
+ train_list.push data
31
+ end
32
+ end
33
+ end
34
+
35
+ def list_url(area_code)
36
+ "http://transit.loco.yahoo.co.jp/traininfo/area/#{area_code}/"
37
+ end
38
+ end
39
+
19
40
  def call
20
41
  list = delay_list
21
42
  return message.reply(found_route) if list.length == 0
@@ -28,28 +49,17 @@ module Ruboty
28
49
 
29
50
  private
30
51
 
31
- def area
32
- return "関東" unless message.match_data.names.include? "area"
33
- message[:area]
34
- end
35
-
36
52
  def route
37
53
  message[:route]
38
54
  end
39
55
 
40
- def area_code
41
- Ruboty::TrainDelay::AREA_SET[area.to_sym]
42
- end
43
-
44
56
  def cause_delay(route)
45
57
  Nokogiri::HTML(open(route[:href]))
46
58
  .css('#mdServiceStatus p').text
47
59
  end
48
60
 
49
61
  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 } }
62
+ self.class.train_list
53
63
  .select { |site| site[:name].include? route }
54
64
  end
55
65
 
@@ -61,10 +71,6 @@ module Ruboty
61
71
  EOS
62
72
  end
63
73
 
64
- def list_url
65
- "http://transit.loco.yahoo.co.jp/traininfo/area/#{area_code}/"
66
- end
67
-
68
74
  def many_route(routes)
69
75
  <<-"EOS"
70
76
  絞り込めませんね。下のどれかでしょうか?
@@ -75,3 +81,5 @@ module Ruboty
75
81
  end
76
82
  end
77
83
  end
84
+
85
+ Ruboty::TrainDelay::Actions::Delay.create_train_list
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module TrainDelay
3
- VERSION = "0.1.1"
3
+ VERSION = "0.2.1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-train_delay
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - akira.takahashi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-13 00:00:00.000000000 Z
11
+ date: 2016-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruboty