ruboty-japan_weather 0.0.2 → 0.0.3

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: 08d3a9f568f26bdc439d4503cc368a7088bbdb7d
4
- data.tar.gz: d26fbd684ed61efd6c000607e40e9c8011487038
3
+ metadata.gz: 2fb7d8c1459f77951f4d0aabaf2bc9ff7f43248c
4
+ data.tar.gz: 2613d0261cd0d6a75c5b143b61a762b8b15cee74
5
5
  SHA512:
6
- metadata.gz: 99c6d8c441b31528e38ca9ddf63796071ea9a5bd618860f34a74520245d3777c23c770e8a0a7ce8c8b6eb9462282d15a1701519b7c28491e7625496cf102b175
7
- data.tar.gz: cf5ca954a2c967fec8539c73f5966cd15166015252d600f0b69851b83bbb854de240405e947deaab19e78b54b7453e3589075dd17ff93b935c240cade732a03a
6
+ metadata.gz: 0827bdf0b025cdc742f28e73b26337e5c329cf72b04219eef97229b1610e5e866ca8cad8cbf3815c8e15a93b43ea911e6c7ad337c3ffc1af7e2cd49c1a4720a7
7
+ data.tar.gz: b5618a56a04747d523b585b3229832b3501eba5aada0e304ce6b8ec1ff964fb99c641883d17bca3891e6430af09e083f512ab27b4c843b4a61232d1c3d7d7160
data/README.md CHANGED
@@ -1,16 +1,16 @@
1
- # Ellen::JapanWeather
2
- An action to tell weather forecast for [Ellen](https://github.com/r7kamura/ellen/) framework.
1
+ # Ruboty::JapanWeather
2
+ An action to tell weather forecast for [Ruboty](https://github.com/r7kamura/ruboty/) framework.
3
3
 
4
4
  ## Installation
5
5
  ```ruby
6
6
  # Gemfile
7
- gem 'ellen-japan_weather'
7
+ gem 'ruboty-japan_weather'
8
8
  ```
9
9
 
10
10
  ## Usage
11
11
  ```
12
- > @ellen 明日の秋葉原の天気教えて
12
+ > @ruboty 明日の秋葉原の天気教えて
13
13
  東京都 千代田区の明日の天気は曇時々雨 最高気温25度 最低気温17度 降水確率は60% です。
14
- > @ellen きょうのテヘランの天気は?
14
+ > @ruboty きょうのテヘランの天気は?
15
15
  イラン テヘランの現在の天気は(17時00分 現在)晴時々曇 です。
16
16
  ```
@@ -8,14 +8,47 @@ module Ruboty
8
8
  private
9
9
 
10
10
  def forecast
11
- look_for(message.body).to_s
11
+ if captures = cmd?(message.match_data.captures)
12
+ look_by_cmd(*captures).to_s
13
+ elsif body = jp?(message.match_data.captures)
14
+ look_by_jp(body).to_s
15
+ else
16
+ message.reply('Unmatched...')
17
+ end
12
18
  end
13
19
 
14
- def look_for(body)
20
+ def look_by_cmd(place, day)
21
+ WeatherJp.get(place, convert(day))
22
+ rescue WeatherJp::WeatherJpError => e
23
+ "Error: #{e}"
24
+ end
25
+
26
+ def look_by_jp(body)
15
27
  WeatherJp.parse(body)
16
28
  rescue WeatherJp::WeatherJpError => e
17
29
  "Error: #{e}"
18
30
  end
31
+
32
+ def cmd?(captures)
33
+ captures[1..2] if captures[1] && captures[2]
34
+ end
35
+
36
+ def jp?(captures)
37
+ captures.first if captures.first
38
+ end
39
+
40
+ def convert(day)
41
+ case day
42
+ when /今日|きょう|今|いま/u
43
+ :today
44
+ when /明日|あした/u
45
+ :tomorrow
46
+ when /明後日|あさって/u
47
+ :day_after_tomorrow
48
+ else
49
+ day
50
+ end
51
+ end
19
52
  end
20
53
  end
21
54
  end
@@ -1,7 +1,11 @@
1
1
  module Ruboty
2
2
  module Handlers
3
3
  class JapanWeather < Base
4
- on /.*の天気/, name: "japan_weather", description: "Reply weather forecast"
4
+ on(
5
+ /((?<jp>.*の天気.*)|tenki\s+(?<place>.*)\s+(?<day>.*))/,
6
+ name: "japan_weather",
7
+ description: "Reply weather forecast"
8
+ )
5
9
 
6
10
  def japan_weather(message)
7
11
  Ruboty::Actions::JapanWeather.new(message).call
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module JapanWeather
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -22,4 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency "weather_jp", "~> 1.0"
23
23
  spec.add_development_dependency "bundler", "~> 1.5"
24
24
  spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
25
26
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruboty-japan_weather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taiki ONO
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: An action to tell weather forecast for ruboty bot framework.
70
84
  email:
71
85
  - taiks.4559@gmail.com