cinch-weatherman 1.0.3 → 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/cinch-weatherman.rb +2 -0
- data/lib/cinch/plugins/weatherman.rb +19 -16
- data/lib/cinch/plugins/weatherman/forecast.rb +25 -0
- data/lib/cinch/plugins/weatherman/version.rb +1 -1
- data/lib/cinch/plugins/weatherman/weather.rb +22 -0
- data/spec/cinch-weatherman_spec.rb +67 -18
- data/spec/spec_helper.rb +8 -2
- metadata +4 -2
data/lib/cinch-weatherman.rb
CHANGED
@@ -13,33 +13,36 @@ module Cinch::Plugins
|
|
13
13
|
|
14
14
|
self.help = 'Use .w <location> to see information on the weather.'
|
15
15
|
|
16
|
-
|
16
|
+
def initialize(*args)
|
17
|
+
super
|
18
|
+
@append = config[:append_forecast] || false
|
19
|
+
end
|
20
|
+
|
21
|
+
match(/(?:w|weather) (.+)/, method: :weather)
|
22
|
+
match(/forecast (.+)/, method: :forecast)
|
17
23
|
|
18
|
-
def
|
24
|
+
def weather(m, query)
|
19
25
|
m.reply get_weather(query)
|
20
26
|
end
|
21
27
|
|
28
|
+
def forecast(m, query)
|
29
|
+
m.reply get_forecast(query)
|
30
|
+
end
|
31
|
+
|
22
32
|
private
|
23
33
|
|
24
34
|
def get_weather(query)
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
message << "and #{temp_f}°F "
|
29
|
-
message << "(last updated about #{updated})"
|
30
|
-
|
31
|
-
message
|
35
|
+
weather = Weather.new(query).to_s
|
36
|
+
weather << " #{Forecast.new(query).append}" if true
|
37
|
+
weather
|
32
38
|
rescue ArgumentError
|
33
39
|
"Sorry, couldn't find #{query}."
|
34
40
|
end
|
35
41
|
|
36
|
-
def
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
data.weather.downcase,
|
41
|
-
Time.parse(data.observation_time).ago.to_words]
|
42
|
-
weather
|
42
|
+
def get_forecast(query)
|
43
|
+
Forecast.new(query).to_s
|
44
|
+
rescue ArgumentError
|
45
|
+
"Sorry, couldn't find #{query}."
|
43
46
|
end
|
44
47
|
end
|
45
48
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Cinch::Plugins
|
3
|
+
class Weatherman
|
4
|
+
class Forecast
|
5
|
+
def initialize(location)
|
6
|
+
@data = WeatherUnderground::Base.new
|
7
|
+
.SimpleForecast(location).days[1]
|
8
|
+
fail ArgumentError if @data.nil?
|
9
|
+
@location = Weather.new(location).location
|
10
|
+
@forecast = @data.conditions.downcase
|
11
|
+
@temp_high = @data.high.fahrenheit.round
|
12
|
+
@temp_low = @data.low.fahrenheit.round
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
"Tommorrow in #{@location}; #{@forecast}, " +
|
17
|
+
"high of #{@temp_high}F, low of #{@temp_low}F."
|
18
|
+
end
|
19
|
+
|
20
|
+
def append
|
21
|
+
to_s.gsub(" in #{@location}", '')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
module Cinch::Plugins
|
3
|
+
class Weatherman
|
4
|
+
class Weather
|
5
|
+
attr_reader :location
|
6
|
+
|
7
|
+
def initialize(location)
|
8
|
+
@data = WeatherUnderground::Base.new
|
9
|
+
.CurrentObservations(location)
|
10
|
+
@location = @data.display_location.first.full
|
11
|
+
@temp = @data.temp_f
|
12
|
+
@conditions = @data.weather.downcase
|
13
|
+
@updated = Time.parse(@data.observation_time).ago.to_words
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
"In #{@location} it is #{@conditions} " +
|
18
|
+
"and #{@temp}F (last updated about #{@updated})."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -8,27 +8,76 @@ describe Cinch::Plugins::Weatherman do
|
|
8
8
|
@bot = make_bot(Cinch::Plugins::Weatherman)
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
describe 'weather' do
|
12
|
+
it 'should allow users to ask for weather by zip' do
|
13
|
+
msg = make_message(@bot, '!weather 94062')
|
14
|
+
get_replies(msg).last.text
|
15
|
+
.should include('In Redwood City, CA it is')
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
it 'should allow users to ask for weather by city, state' do
|
19
|
+
msg = make_message(@bot, '!weather redwood city, ca')
|
20
|
+
get_replies(msg).last.text
|
21
|
+
.should include('In Redwood City, CA it is')
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should return temps' do
|
25
|
+
msg = make_message(@bot, '!weather redwood city, ca')
|
26
|
+
get_replies(msg).last.text
|
27
|
+
.should match(/\d+F/)
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'should allow users to ask for weather by airport code' do
|
31
|
+
msg = make_message(@bot, '!weather SFO')
|
32
|
+
get_replies(msg).last.text
|
33
|
+
.should include('In San Francisco International, CA it is')
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'should return an error when location not found' do
|
37
|
+
msg = make_message(@bot, '!weather 34')
|
38
|
+
get_replies(msg).last.text
|
39
|
+
.should include('Sorry, couldn\'t find 34.')
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'should allow users to append forecasts' do
|
43
|
+
bot = make_bot(Cinch::Plugins::Weatherman, { append_forecast: true })
|
44
|
+
msg = make_message(@bot, '!weather 94062')
|
45
|
+
message = get_replies(msg).first.text
|
46
|
+
message.should include('In Redwood City, CA it is')
|
47
|
+
message.should include('Tommorrow;')
|
48
|
+
end
|
22
49
|
|
23
|
-
it 'should allow users to ask for weather by airport code' do
|
24
|
-
msg = make_message(@bot, '!weather SFO')
|
25
|
-
get_replies(msg).last.text.
|
26
|
-
should include('In San Francisco International, CA it is')
|
27
50
|
end
|
28
51
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
52
|
+
describe 'forecast' do
|
53
|
+
it 'should allow users to ask for forecast by zip' do
|
54
|
+
msg = make_message(@bot, '!forecast 94062')
|
55
|
+
get_replies(msg).last.text
|
56
|
+
.should include('Tommorrow in Redwood City, CA;')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'should allow users to ask for forecast by city, state' do
|
60
|
+
msg = make_message(@bot, '!forecast redwood city, ca')
|
61
|
+
get_replies(msg).last.text
|
62
|
+
.should include('Tommorrow in Redwood City, CA;')
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should allow users to ask for forecast by airport code' do
|
66
|
+
msg = make_message(@bot, '!forecast SFO')
|
67
|
+
get_replies(msg).last.text
|
68
|
+
.should include('Tommorrow in San Francisco International, CA;')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should return an error when location not found' do
|
72
|
+
msg = make_message(@bot, '!forecast 34')
|
73
|
+
get_replies(msg).last.text
|
74
|
+
.should include('Sorry, couldn\'t find 34.')
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should return temps' do
|
78
|
+
msg = make_message(@bot, '!weather redwood city, ca')
|
79
|
+
get_replies(msg).last.text
|
80
|
+
.should match(/\d+F/)
|
81
|
+
end
|
33
82
|
end
|
34
83
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
require 'coveralls'
|
2
|
-
|
2
|
+
require 'simplecov'
|
3
|
+
|
4
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
7
|
+
]
|
8
|
+
SimpleCov.start
|
9
|
+
|
3
10
|
require 'cinch-weatherman'
|
4
11
|
require 'cinch/test'
|
5
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cinch-weatherman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-02-
|
13
|
+
date: 2014-02-28 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -156,7 +156,9 @@ files:
|
|
156
156
|
- cinch-weatherman.gemspec
|
157
157
|
- lib/cinch-weatherman.rb
|
158
158
|
- lib/cinch/plugins/weatherman.rb
|
159
|
+
- lib/cinch/plugins/weatherman/forecast.rb
|
159
160
|
- lib/cinch/plugins/weatherman/version.rb
|
161
|
+
- lib/cinch/plugins/weatherman/weather.rb
|
160
162
|
- spec/cinch-weatherman_spec.rb
|
161
163
|
- spec/spec_helper.rb
|
162
164
|
homepage: https://github.com/canonical-hackers/cinch-weatherman
|