anemoi 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/Gemfile +3 -0
- data/LICENSE +22 -0
- data/README.md +102 -0
- data/Rakefile +2 -0
- data/anemoi.gemspec +21 -0
- data/bin/anemoi +15 -0
- data/lib/anemoi/area_parser.rb +205 -0
- data/lib/anemoi/client.rb +60 -0
- data/lib/anemoi/hash.rb +25 -0
- data/lib/anemoi/version.rb +3 -0
- data/lib/anemoi.rb +15 -0
- data/spec/anemoi/area_parser_spec.rb +48 -0
- data/spec/anemoi/client_spec.rb +53 -0
- data/spec/spec_helper.rb +4 -0
- metadata +112 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Ryo NAKAMURA
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Anemoi
|
2
|
+
|
3
|
+
Anemoiに日本語で天気を聞くと天気予報を教えてくれます。
|
4
|
+
天気予報は Livedoor Weather Web Service ( [http://weather.livedoor.com/weather_hacks/](http://weather.livedoor.com/weather_hacks/) )からお借りしています。
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
gem 'anemoi'
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install anemoi
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
```
|
23
|
+
$ anemoi 明日の天気
|
24
|
+
```
|
25
|
+
|
26
|
+
or
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
require 'anemoi'
|
30
|
+
require 'awesome_print'
|
31
|
+
|
32
|
+
ap Anemoi.get_weather('明日の群馬の天気ください')
|
33
|
+
|
34
|
+
{
|
35
|
+
:specified => {
|
36
|
+
:date => :tomorrow,
|
37
|
+
:city => {
|
38
|
+
:id => 58,
|
39
|
+
:name => "前橋"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
:forecastday => :tomorrow,
|
43
|
+
:forecastdate => "Sun, 22 Jul 2012 00:00:00 +0900",
|
44
|
+
:day => "Sunday",
|
45
|
+
:location => {
|
46
|
+
:area => "関東",
|
47
|
+
:pref => "群馬県",
|
48
|
+
:city => "前橋"
|
49
|
+
},
|
50
|
+
:weather => "曇時々雨",
|
51
|
+
:description => "北部では、22日朝まで土砂災害に注意して下さい。群馬県では、22日朝まで濃霧による視程障害に注意して下さい。\n\nオホーツク海高気圧が東日本に張り出しています...",
|
52
|
+
:temperature => {
|
53
|
+
:max => {
|
54
|
+
:celsius => "25",
|
55
|
+
:fahrenheit => "77"
|
56
|
+
},
|
57
|
+
:min => {
|
58
|
+
:celsius => "19",
|
59
|
+
:fahrenheit => "66.2"
|
60
|
+
}
|
61
|
+
}
|
62
|
+
}
|
63
|
+
|
64
|
+
ac = Anemoi::Client.new(default_city: "京都")
|
65
|
+
ap ac.get_weather('明日のお天気お願いします〜〜')
|
66
|
+
|
67
|
+
{
|
68
|
+
:specified => {
|
69
|
+
:date => :tomorrow,
|
70
|
+
:city => nil
|
71
|
+
},
|
72
|
+
:forecastday => :tomorrow,
|
73
|
+
:forecastdate => "Sun, 22 Jul 2012 00:00:00 +0900",
|
74
|
+
:day => "Sunday",
|
75
|
+
:location => {
|
76
|
+
:area => "近畿",
|
77
|
+
:pref => "京都府",
|
78
|
+
:city => "京都"
|
79
|
+
},
|
80
|
+
:weather => "曇のち雨",
|
81
|
+
:description => "京都府では、21日夜遅くまで急な強い雨や落雷に注意して下さい。\n\n近畿地方は、湿った空気の影響で、雲が広がり、中部では非常に激しい雨の降っているところがあ...",
|
82
|
+
:temperature => {
|
83
|
+
:max => {
|
84
|
+
:celsius => "29",
|
85
|
+
:fahrenheit => "84.2"
|
86
|
+
},
|
87
|
+
:min => {
|
88
|
+
:celsius => "23",
|
89
|
+
:fahrenheit => "73.4"
|
90
|
+
}
|
91
|
+
}
|
92
|
+
}
|
93
|
+
```
|
94
|
+
|
95
|
+
Livedoor Weather Web Service に依存しているため、取得できる地域は [RSSフィード一覧](http://weather.livedoor.com/weather_hacks/rss_feed_list.html) の142箇所に限られます。
|
96
|
+
今日、明日、明後日の3日間に対応。
|
97
|
+
|
98
|
+
## Dependency
|
99
|
+
|
100
|
+
gem 'horai'
|
101
|
+
gem 'httparty'
|
102
|
+
|
data/Rakefile
ADDED
data/anemoi.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/anemoi/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["kkosuge"]
|
6
|
+
gem.email = ["kkosuge@about.me"]
|
7
|
+
gem.description = %q{get weather forecast from expression with natural language (ONLY IN JAPANESE)}
|
8
|
+
gem.summary = %q{get weather forecast from expression with natural language (ONLY IN JAPANESE)}
|
9
|
+
gem.homepage = "https://github.com/kkosuge/Anemoi"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "anemoi"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Anemoi::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency "httparty"
|
19
|
+
gem.add_dependency "horai"
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
end
|
data/bin/anemoi
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "pp"
|
4
|
+
require "date"
|
5
|
+
|
6
|
+
text = ARGV[0]
|
7
|
+
unless text
|
8
|
+
puts "Usage: anemoi [明日の天気]"
|
9
|
+
exit!
|
10
|
+
end
|
11
|
+
|
12
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
13
|
+
require "anemoi"
|
14
|
+
|
15
|
+
pp Anemoi.get_weather(text)
|
@@ -0,0 +1,205 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Anemoi
|
4
|
+
class AreaParser
|
5
|
+
ID_BY_CITY = {
|
6
|
+
"稚内" => 1,
|
7
|
+
"旭川" => 2,
|
8
|
+
"留萌" => 3,
|
9
|
+
"札幌" => 4,
|
10
|
+
"岩見沢" => 5,
|
11
|
+
"倶知安" => 6,
|
12
|
+
"網走" => 7,
|
13
|
+
"北見" => 8,
|
14
|
+
"紋別" => 9,
|
15
|
+
"根室" => 10,
|
16
|
+
"釧路" => 11,
|
17
|
+
"帯広" => 12,
|
18
|
+
"室蘭" => 13,
|
19
|
+
"浦河" => 14,
|
20
|
+
"函館" => 15,
|
21
|
+
"江差" => 16,
|
22
|
+
"青森" => 17,
|
23
|
+
"むつ" => 18,
|
24
|
+
"八戸" => 19,
|
25
|
+
"秋田" => 20,
|
26
|
+
"横手" => 21,
|
27
|
+
"盛岡" => 22,
|
28
|
+
"大船渡" => 24,
|
29
|
+
"仙台" => 25,
|
30
|
+
"白石" => 26,
|
31
|
+
"山形" => 27,
|
32
|
+
"米沢" => 28,
|
33
|
+
"酒田" => 29,
|
34
|
+
"新庄" => 30,
|
35
|
+
"福島" => 31,
|
36
|
+
"小名浜" => 32,
|
37
|
+
"若松" => 33,
|
38
|
+
"水戸" => 54,
|
39
|
+
"土浦" => 55,
|
40
|
+
"宇都宮" => 56,
|
41
|
+
"大田原" => 57,
|
42
|
+
"前橋" => 58,
|
43
|
+
"みなかみ" => 59,
|
44
|
+
"さいたま" => 60,
|
45
|
+
"熊谷" => 61,
|
46
|
+
"秩父" => 62,
|
47
|
+
"東京" => 63,
|
48
|
+
"大島" => 64,
|
49
|
+
"八丈島" => 65,
|
50
|
+
"父島" => 66,
|
51
|
+
"千葉" => 67,
|
52
|
+
"銚子" => 68,
|
53
|
+
"館山" => 69,
|
54
|
+
"横浜" => 70,
|
55
|
+
"小田原" => 71,
|
56
|
+
"甲府" => 75,
|
57
|
+
"河口湖" => 76,
|
58
|
+
"富山" => 44,
|
59
|
+
"伏木" => 45,
|
60
|
+
"金沢" => 46,
|
61
|
+
"輪島" => 47,
|
62
|
+
"福井" => 48,
|
63
|
+
"敦賀" => 49,
|
64
|
+
"新潟" => 50,
|
65
|
+
"長岡" => 51,
|
66
|
+
"高田" => 52,
|
67
|
+
"相川" => 53,
|
68
|
+
"長野" => 72,
|
69
|
+
"松本" => 73,
|
70
|
+
"飯田" => 74,
|
71
|
+
"静岡" => 34,
|
72
|
+
"網代" => 35,
|
73
|
+
"三島" => 36,
|
74
|
+
"浜松" => 37,
|
75
|
+
"名古屋" => 38,
|
76
|
+
"豊橋" => 39,
|
77
|
+
"岐阜" => 40,
|
78
|
+
"高山" => 41,
|
79
|
+
"尾鷲" => 43,
|
80
|
+
"大津" => 77,
|
81
|
+
"彦根" => 78,
|
82
|
+
"京都" => 79,
|
83
|
+
"舞鶴" => 80,
|
84
|
+
"大阪" => 81,
|
85
|
+
"神戸" => 82,
|
86
|
+
"豊岡" => 83,
|
87
|
+
"奈良" => 84,
|
88
|
+
"風屋" => 85,
|
89
|
+
"和歌山" => 86,
|
90
|
+
"潮岬" => 87,
|
91
|
+
"岡山" => 88,
|
92
|
+
"津山" => 89,
|
93
|
+
"広島" => 90,
|
94
|
+
"庄原" => 91,
|
95
|
+
"松江" => 92,
|
96
|
+
"浜田" => 93,
|
97
|
+
"西郷" => 94,
|
98
|
+
"鳥取" => 95,
|
99
|
+
"米子" => 96,
|
100
|
+
"下関" => 97,
|
101
|
+
"山口" => 98,
|
102
|
+
"柳井" => 99,
|
103
|
+
"萩" => 100,
|
104
|
+
"徳島" => 101,
|
105
|
+
"日和佐" => 102,
|
106
|
+
"高松" => 103,
|
107
|
+
"松山" => 104,
|
108
|
+
"新居浜" => 105,
|
109
|
+
"宇和島" => 106,
|
110
|
+
"高知" => 107,
|
111
|
+
"室戸" => 108,
|
112
|
+
"清水" => 109,
|
113
|
+
"福岡" => 110,
|
114
|
+
"八幡" => 111,
|
115
|
+
"飯塚" => 112,
|
116
|
+
"久留米" => 113,
|
117
|
+
"大分" => 114,
|
118
|
+
"中津" => 115,
|
119
|
+
"日田" => 116,
|
120
|
+
"佐伯" => 117,
|
121
|
+
"長崎" => 118,
|
122
|
+
"佐世保" => 119,
|
123
|
+
"厳原" => 120,
|
124
|
+
"福江" => 121,
|
125
|
+
"佐賀" => 122,
|
126
|
+
"伊万里" => 123,
|
127
|
+
"熊本" => 124,
|
128
|
+
"阿蘇乙姫" => 125,
|
129
|
+
"牛深" => 126,
|
130
|
+
"人吉" => 127,
|
131
|
+
"宮崎" => 128,
|
132
|
+
"延岡" => 129,
|
133
|
+
"都城" => 130,
|
134
|
+
"高千穂" => 131,
|
135
|
+
"鹿児島" => 132,
|
136
|
+
"鹿屋" => 133,
|
137
|
+
"種子島" => 134,
|
138
|
+
"名瀬" => 135,
|
139
|
+
"那覇" => 136,
|
140
|
+
"名護" => 137,
|
141
|
+
"久米島" => 138,
|
142
|
+
"南大東島" => 139,
|
143
|
+
"宮古島" => 140,
|
144
|
+
"石垣島" => 141,
|
145
|
+
"与那国島" => 142,
|
146
|
+
"津" => 42,
|
147
|
+
"宮古" => 23
|
148
|
+
}
|
149
|
+
|
150
|
+
CITY_BY_PREF = {
|
151
|
+
"北海" => "札幌",
|
152
|
+
"岩手" => "盛岡",
|
153
|
+
"宮城" => "仙台",
|
154
|
+
"茨城" => "水戸",
|
155
|
+
"栃木" => "宇都宮",
|
156
|
+
"群馬" => "前橋",
|
157
|
+
"埼玉" => "さいたま",
|
158
|
+
"神奈川" => "横浜",
|
159
|
+
"山梨" => "甲府",
|
160
|
+
"富山" => "富山",
|
161
|
+
"石川" => "金沢",
|
162
|
+
"長野" => "長野",
|
163
|
+
"愛知" => "名古屋",
|
164
|
+
"三重" => "津",
|
165
|
+
"滋賀" => "大津",
|
166
|
+
"兵庫" => "神戸",
|
167
|
+
"島根" => "松江",
|
168
|
+
"香川" => "高松",
|
169
|
+
"愛媛" => "松山",
|
170
|
+
"沖縄" => "那覇"
|
171
|
+
}
|
172
|
+
|
173
|
+
@@city_regexp = /#{ID_BY_CITY.map(&:first).join('|')}/
|
174
|
+
@@pref_regexp = /#{CITY_BY_PREF.map(&:first).join('|')}/
|
175
|
+
|
176
|
+
class << self
|
177
|
+
def parse(text)
|
178
|
+
text = canonical_city(text)
|
179
|
+
info_by_city(city_by_pref(text))
|
180
|
+
end
|
181
|
+
|
182
|
+
def city_by_pref(text)
|
183
|
+
if city = text.match(@@pref_regexp)
|
184
|
+
city = city.values_at(0).first
|
185
|
+
text.gsub! city, CITY_BY_PREF[city]
|
186
|
+
end
|
187
|
+
text
|
188
|
+
end
|
189
|
+
|
190
|
+
def info_by_city(text)
|
191
|
+
city = text.match(@@city_regexp)
|
192
|
+
if city
|
193
|
+
name = city.values_at(0).first
|
194
|
+
return { :id => ID_BY_CITY[name], :name => name }
|
195
|
+
end
|
196
|
+
nil
|
197
|
+
end
|
198
|
+
|
199
|
+
def canonical_city(text)
|
200
|
+
text.gsub!("東京都","東京")
|
201
|
+
text
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Anemoi
|
4
|
+
class Client
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
WEATHER_URL = "http://weather.livedoor.com/forecast/webservice/rest/v1"
|
8
|
+
AREA_TABLE_URL = "http://weather.livedoor.com/forecast/rss/forecastmap.xml"
|
9
|
+
|
10
|
+
def initialize(options={})
|
11
|
+
options[:default_city] ||= "東京"
|
12
|
+
@default_city = AreaParser.parse(options[:default_city])
|
13
|
+
@default_date = options[:default_date] || :today
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_weather(text, opts = {})
|
17
|
+
specified_city = AreaParser.parse(text)
|
18
|
+
specified_date = horai_date_parse(text)
|
19
|
+
city = specified_city || @default_city
|
20
|
+
date = specified_date || @default_date
|
21
|
+
query = { :city => city[:id], :day => date }.merge(opts)
|
22
|
+
hash = get WEATHER_URL, :query => query
|
23
|
+
|
24
|
+
{
|
25
|
+
:specified => {
|
26
|
+
:date => specified_date,
|
27
|
+
:city => specified_city
|
28
|
+
},
|
29
|
+
:forecastday => date,
|
30
|
+
:forecastdate => hash["lwws"]["forecastdate"],
|
31
|
+
:day => hash["lwws"]["day"],
|
32
|
+
:location => hash["lwws"]["location"],
|
33
|
+
:weather => hash["lwws"]["telop"],
|
34
|
+
:description => hash["lwws"]["description"],
|
35
|
+
:temperature => hash["lwws"]["temperature"]
|
36
|
+
}.deep_symbolize_keys
|
37
|
+
rescue ParseError
|
38
|
+
nil
|
39
|
+
end
|
40
|
+
|
41
|
+
def horai_date_parse(text)
|
42
|
+
@jajp ||= Horai::JaJP.new
|
43
|
+
date = @jajp.parse(text)
|
44
|
+
now = Date.today
|
45
|
+
case date
|
46
|
+
when now + 0; :today
|
47
|
+
when now + 1; :tomorrow
|
48
|
+
when now + 2; :day_after_tomorrow
|
49
|
+
else nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
# use HTTParty.get
|
56
|
+
def get(*args)
|
57
|
+
self.class.get(*args)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
data/lib/anemoi/hash.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
class Hash
|
2
|
+
def transform_keys
|
3
|
+
result = {}
|
4
|
+
each_key do |key|
|
5
|
+
result[yield(key)] = self[key]
|
6
|
+
end
|
7
|
+
result
|
8
|
+
end
|
9
|
+
|
10
|
+
def symbolize_keys
|
11
|
+
transform_keys{ |key| key.to_sym rescue key }
|
12
|
+
end
|
13
|
+
|
14
|
+
def deep_transform_keys(&block)
|
15
|
+
result = {}
|
16
|
+
each do |key, value|
|
17
|
+
result[yield(key)] = value.is_a?(Hash) ? value.deep_transform_keys(&block) : value
|
18
|
+
end
|
19
|
+
result
|
20
|
+
end
|
21
|
+
|
22
|
+
def deep_symbolize_keys
|
23
|
+
deep_transform_keys{ |key| key.to_sym rescue key }
|
24
|
+
end
|
25
|
+
end
|
data/lib/anemoi.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "httparty"
|
2
|
+
require "horai"
|
3
|
+
require "date"
|
4
|
+
|
5
|
+
require "anemoi/version"
|
6
|
+
require "anemoi/hash"
|
7
|
+
require "anemoi/area_parser"
|
8
|
+
require "anemoi/client"
|
9
|
+
|
10
|
+
module Anemoi
|
11
|
+
def self.get_weather(text)
|
12
|
+
@@instance ||= Client.new
|
13
|
+
@@instance.get_weather(text)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Anemoi::AreaParser do
|
6
|
+
describe "#city_by_pref" do
|
7
|
+
it "県を入力して県庁所在地を出力する" do
|
8
|
+
city = Anemoi::AreaParser.city_by_pref('群馬')
|
9
|
+
city.should == '前橋'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "県が含まれなかったら入力をそのまま返す" do
|
13
|
+
city = Anemoi::AreaParser.city_by_pref('ニャッス')
|
14
|
+
city.should == 'ニャッス'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#info_by_city" do
|
19
|
+
it "町が含まれたテキストからidと町の名前を返す" do
|
20
|
+
Anemoi::AreaParser.info_by_city('前橋〜〜').should == { :id => 58, :name => '前橋' }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe "#parse" do
|
25
|
+
it "県が含まれた文字列からidを返す" do
|
26
|
+
Anemoi::AreaParser.parse('明日の群馬の天気など')[:id].should == 58
|
27
|
+
end
|
28
|
+
|
29
|
+
it "県が含まれなかったらnilを返す" do
|
30
|
+
Anemoi::AreaParser.parse('明日の天気など').should be_nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it "京都東京都" do
|
34
|
+
Anemoi::AreaParser.info_by_city('京都')[:id].should == 79
|
35
|
+
Anemoi::AreaParser.info_by_city('東京都')[:id].should == 63
|
36
|
+
end
|
37
|
+
|
38
|
+
it "津" do
|
39
|
+
Anemoi::AreaParser.info_by_city('津')[:name].should == '津'
|
40
|
+
Anemoi::AreaParser.info_by_city('大津')[:name].should == '大津'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "宮古島宮古" do
|
44
|
+
Anemoi::AreaParser.info_by_city('宮古')[:name].should == '宮古'
|
45
|
+
Anemoi::AreaParser.info_by_city('宮古島')[:name].should == '宮古島'
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
|
5
|
+
describe Anemoi::Client do
|
6
|
+
describe "#horai_date_parse" do
|
7
|
+
before do
|
8
|
+
@anemoi = Anemoi::Client.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "明日" do
|
12
|
+
@anemoi.horai_date_parse("明日の天気").should == :tomorrow
|
13
|
+
end
|
14
|
+
it "明後日" do
|
15
|
+
@anemoi.horai_date_parse("明後日の天気").should == :day_after_tomorrow
|
16
|
+
end
|
17
|
+
it "指定がない場合" do
|
18
|
+
@anemoi.horai_date_parse("あれ").should be_nil
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#get_weather" do
|
23
|
+
result = Anemoi::Client.new.get_weather("群馬の天気")
|
24
|
+
it "result" do
|
25
|
+
result[:location][:city].should == "前橋"
|
26
|
+
result[:forecastday].should == :today
|
27
|
+
result[:weather].should =~ /[晴曇雨]/
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "指定した日と場所" do
|
31
|
+
it "指定した場合" do
|
32
|
+
result = Anemoi::Client.new.get_weather("群馬の天気")
|
33
|
+
result[:specified][:city].should be_kind_of Hash
|
34
|
+
end
|
35
|
+
it "指定しない場合[:specified][:city]はnil" do
|
36
|
+
result = Anemoi::Client.new.get_weather("天気")
|
37
|
+
result[:specified][:city].should be_nil
|
38
|
+
end
|
39
|
+
it "時間を指定しない場合は今日" do
|
40
|
+
result = Anemoi::Client.new.get_weather("天気")
|
41
|
+
result[:forecastday].should == :today
|
42
|
+
end
|
43
|
+
it "場所を指定しない場合は東京" do
|
44
|
+
result = Anemoi::Client.new.get_weather("天気")
|
45
|
+
result[:location][:city].should == "東京"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "Anemoi.get_weather" do
|
51
|
+
Anemoi.get_weather("明日の広島")[:weather].should =~ /[晴曇雨]/
|
52
|
+
end
|
53
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,112 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: anemoi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- kkosuge
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-21 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: httparty
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: horai
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: get weather forecast from expression with natural language (ONLY IN JAPANESE)
|
63
|
+
email:
|
64
|
+
- kkosuge@about.me
|
65
|
+
executables:
|
66
|
+
- anemoi
|
67
|
+
extensions: []
|
68
|
+
extra_rdoc_files: []
|
69
|
+
files:
|
70
|
+
- .gitignore
|
71
|
+
- Gemfile
|
72
|
+
- LICENSE
|
73
|
+
- README.md
|
74
|
+
- Rakefile
|
75
|
+
- anemoi.gemspec
|
76
|
+
- bin/anemoi
|
77
|
+
- lib/anemoi.rb
|
78
|
+
- lib/anemoi/area_parser.rb
|
79
|
+
- lib/anemoi/client.rb
|
80
|
+
- lib/anemoi/hash.rb
|
81
|
+
- lib/anemoi/version.rb
|
82
|
+
- spec/anemoi/area_parser_spec.rb
|
83
|
+
- spec/anemoi/client_spec.rb
|
84
|
+
- spec/spec_helper.rb
|
85
|
+
homepage: https://github.com/kkosuge/Anemoi
|
86
|
+
licenses: []
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
none: false
|
99
|
+
requirements:
|
100
|
+
- - ! '>='
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 1.8.23
|
106
|
+
signing_key:
|
107
|
+
specification_version: 3
|
108
|
+
summary: get weather forecast from expression with natural language (ONLY IN JAPANESE)
|
109
|
+
test_files:
|
110
|
+
- spec/anemoi/area_parser_spec.rb
|
111
|
+
- spec/anemoi/client_spec.rb
|
112
|
+
- spec/spec_helper.rb
|