ruboty-livedoor_weather 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -1
- data/lib/ruboty/livedoor_weather/client.rb +22 -2
- data/lib/ruboty/livedoor_weather/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92db96ea940c9ae3582cd0a2d70c0a171a63b065
|
4
|
+
data.tar.gz: 831caf452894e8ebdf4e567c88ab8f5a0a2267eb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a96daf9e5ced354fd97275ba562bd0c9dcde25b3a6debe02d5f642b1172ea6ebdf07b1570455fce4d10a8a111b2f1e40d712448a6c78352f977225c932eab427
|
7
|
+
data.tar.gz: dfb4756bab7c17f6f58c3c3deca0bfd487b1869131c3002b2c807fde8cd645ee4f6232dc9b6fc53507535b2fe543fb622a9c950a393800250ffd12ba5fcf75ea
|
data/README.md
CHANGED
@@ -12,6 +12,9 @@ gem 'ruboty-livedoor_weather'
|
|
12
12
|
|
13
13
|
## Usage
|
14
14
|
|
15
|
+
|
16
|
+
### Simple way
|
17
|
+
|
15
18
|
Talk to your ruboty:
|
16
19
|
|
17
20
|
```
|
@@ -20,15 +23,26 @@ ruboty livedoor_weather
|
|
20
23
|
|
21
24
|
Then shows forecasts specified by `ENV['LDW_CITY']` (default : '東京').
|
22
25
|
|
26
|
+
### Specify area
|
27
|
+
|
23
28
|
You can specify city to show forecast:
|
24
29
|
|
25
30
|
```
|
26
31
|
ruboty livedoor_weather 種子島
|
27
32
|
```
|
28
33
|
|
34
|
+
### Also sho pinpoint locations
|
35
|
+
|
36
|
+
You can specify locations to show URL to pinpoint location page:
|
37
|
+
|
38
|
+
```
|
39
|
+
ruboty livedoor_weather 京都 京都市中京区 長岡京市
|
40
|
+
```
|
41
|
+
|
42
|
+
Show all pinpoint locations if location list includes `all`.
|
43
|
+
|
29
44
|
List of cities is [here](http://weather.livedoor.com/forecast/rss/primary_area.xml).
|
30
45
|
|
31
46
|
## License
|
32
47
|
|
33
48
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
34
|
-
|
@@ -19,9 +19,23 @@ module Ruboty::LivedoorWeather
|
|
19
19
|
|
20
20
|
response = RestClient.get(ENDPOINT, params: { city: cc })
|
21
21
|
json = JSON.parse(response)
|
22
|
-
|
23
22
|
forecasts = format_forecasts(json['forecasts'])
|
24
|
-
|
23
|
+
|
24
|
+
result = [
|
25
|
+
"*#{@city}* の天気予報です。",
|
26
|
+
forecasts,
|
27
|
+
"\n",
|
28
|
+
remove_linebreak(json['description']['text']),
|
29
|
+
]
|
30
|
+
|
31
|
+
pinpoint_locations = format_pinpoint_locations(json['pinpointLocations'], @locations)
|
32
|
+
|
33
|
+
unless pinpoint_locations.empty?
|
34
|
+
result += ["\n", "【ピンポイント天気】"]
|
35
|
+
result += pinpoint_locations
|
36
|
+
end
|
37
|
+
|
38
|
+
result.join("\n")
|
25
39
|
end
|
26
40
|
|
27
41
|
private
|
@@ -51,6 +65,12 @@ module Ruboty::LivedoorWeather
|
|
51
65
|
"気温:#{min}/#{max} #{unit == 'celsius' ? 'C' : 'F' }"
|
52
66
|
end
|
53
67
|
|
68
|
+
def format_pinpoint_locations(data, locations)
|
69
|
+
data.find_all { |d|
|
70
|
+
locations.include?('all') || locations.include?(d['name'])
|
71
|
+
}.map { |d| "#{d['name']} : #{d['link']}" }
|
72
|
+
end
|
73
|
+
|
54
74
|
def remove_linebreak(forecast_description)
|
55
75
|
forecast_description.gsub(/[^\n。】]\n/) { |m| m.delete("\n") }
|
56
76
|
end
|