lita-forecast 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77dfaba52cdabe395bd4f60f7567b5b231dd516c
4
- data.tar.gz: e22e704c6c6d0e8b3a6e3263f9b485d98d1a0a2d
3
+ metadata.gz: 0ca70495987b9e91016e2d017d053fc7826b46bf
4
+ data.tar.gz: 7012323fbbdff18f5dd4d06bb49ec2c869517745
5
5
  SHA512:
6
- metadata.gz: fcfd0ca40632c9157be12976da76c38c9912a76d475a35964d60437efa4c1b617844271f26ad5b3defa16f8f405ac0e0db7714123774e3a7a6a78eb2125e0d54
7
- data.tar.gz: a57c3bef445dac1ce209c571482bc0505119d5cec6a34e203a707cbf27e6088b703520efb5e3eefc53ec1a91a58910ad9226d7a15c6907dfc4d51ff921c63688
6
+ metadata.gz: 6c23171c3445e152ebc2c387eced2664e8df2b349714642c571dbe942417eb007e68541d15f3932348c3fb2b42fc8c954cea4c727aa766309ecb42299c229f4e
7
+ data.tar.gz: 873076adb7b04093a1dad99307d350f56e0adef16d52291c10f7cff7fab060a2b83db122eb235d64c83fc3e3bcb16b10ccc933011366ef93dc643e4d86d5ab9e
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,9 @@
1
+ lita-forecast
2
+ =============
3
+
4
+ CONTRIBUTING
5
+ ------------
6
+ Something wrong or you want to submit an improvement? Fork the repo, make your
7
+ changes on a feature branch, write some tests, and submit a pull request. I
8
+ only ask that the commits have useful information and use proper/complete
9
+ sentences.
data/README.md CHANGED
@@ -17,10 +17,9 @@ provided in the `LICENSE` file.
17
17
 
18
18
  CONTRIBUTING
19
19
  ------------
20
- Something wrong or you want to submit an improvement? Fork the repo, make your
21
- changes on a feature branch, write some tests, and submit a pull request. I
22
- only ask that the commits have useful information and use proper/complete
23
- sentences.
20
+ See [CONTRIBUTION.md](https://github.com/theckman/lita-forecast/blob/master/CONTRIBUTING.md)
21
+ for information on contributing back to this project.
22
+
24
23
 
25
24
  INSTALLATION
26
25
  ------------
@@ -7,6 +7,8 @@ module LitaForecast
7
7
  class Current
8
8
  include LitaForecast::Mixins
9
9
 
10
+ INFO_UNAVAIL ||= 'Information unavailable. :('
11
+
10
12
  def initialize(forecast)
11
13
  @f = forecast
12
14
  end
@@ -56,10 +58,14 @@ module LitaForecast
56
58
 
57
59
  def next_hour
58
60
  @f['minutely']['summary']
61
+ rescue
62
+ INFO_UNAVAIL
59
63
  end
60
64
 
61
65
  def today
62
66
  @f['hourly']['summary']
67
+ rescue
68
+ INFO_UNAVAIL
63
69
  end
64
70
  end
65
71
  end
@@ -22,10 +22,33 @@ module LitaForecast
22
22
  gl = geo_location(g)
23
23
  loc = { lat: g['geometry']['location']['lat'],
24
24
  lng: g['geometry']['location']['lng'],
25
- desc: "#{gl[:city]}, #{gl[:state]}" }
25
+ desc: desc(gl) }
26
26
  end
27
27
 
28
28
  loc
29
29
  end
30
+
31
+ private
32
+
33
+ def desc(loc)
34
+ l = ''
35
+ h = { c: city(loc), s: state(loc) }
36
+ l << h[:c]
37
+ l << ', ' unless h[:c].empty? || h[:s].empty?
38
+ l << h[:s]
39
+ l
40
+ end
41
+
42
+ def city(loc)
43
+ c = ''
44
+ c << loc[:city] if loc[:city].is_a?(String) && !loc[:city].empty?
45
+ c
46
+ end
47
+
48
+ def state(loc)
49
+ s = ''
50
+ s << loc[:state] if loc[:state].is_a?(String) && !loc[:state].empty?
51
+ s
52
+ end
30
53
  end
31
54
  end
@@ -24,5 +24,5 @@
24
24
  # LitaForcast module, just for version handling
25
25
  #
26
26
  module LitaForecast
27
- VERSION = '0.1.3'
27
+ VERSION = '0.1.4'
28
28
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |g|
21
21
  g.test_files = %x(git ls-files spec/*).split
22
22
  g.files = %x(git ls-files).split
23
23
 
24
- g.add_development_dependency 'bundler', '~> 1.5.3'
24
+ g.add_development_dependency 'bundler', '~> 1.5'
25
25
  g.add_development_dependency 'rake', '~> 10.2.2'
26
26
  g.add_development_dependency 'rubocop', '~> 0.19.1'
27
27
  g.add_development_dependency 'rspec', '>= 3.0.0.beta2'
@@ -20,7 +20,25 @@ describe LitaForecast::Current do
20
20
  'flags' => { 'units' => 'us' }
21
21
  }
22
22
  end
23
+ let(:missing_info_forecast) do
24
+ {
25
+ 'currently' => {
26
+ 'temperature' => 100.11,
27
+ 'apparentTemperature' => 102.11,
28
+ 'summary' => 'weather',
29
+ 'windBearing' => 0,
30
+ 'windSpeed' => 5.11,
31
+ 'humidity' => 0.10,
32
+ 'dewPoint' => 20.11,
33
+ 'pressure' => 1020.11,
34
+ 'cloudCover' => 0.01
35
+ },
36
+ 'flags' => { 'units' => 'us' }
37
+ }
38
+ end
23
39
  let(:current) { described_class.new(forecast) }
40
+ let(:current_no_summary) { described_class.new(missing_info_forecast) }
41
+ let(:summary_fail) { 'Information unavailable. :(' }
24
42
 
25
43
  describe '#new' do
26
44
  context 'when given more than one arg' do
@@ -50,6 +68,14 @@ describe LitaForecast::Current do
50
68
  end
51
69
  end
52
70
 
71
+ describe '::INFO_UNAVAIL' do
72
+ subject { LitaForecast::Current::INFO_UNAVAIL }
73
+
74
+ it { should be_an_instance_of String }
75
+
76
+ it { should eql 'Information unavailable. :(' }
77
+ end
78
+
53
79
  describe '.currently' do
54
80
  context 'when given one arg' do
55
81
  it 'should raise error ArgumentError' do
@@ -210,7 +236,7 @@ describe LitaForecast::Current do
210
236
  end
211
237
  end
212
238
 
213
- context 'when passed no args' do
239
+ context 'when there is a summary' do
214
240
  subject { current.send(:next_hour) }
215
241
  let(:next_hour) { 'minutely weather' }
216
242
 
@@ -218,6 +244,14 @@ describe LitaForecast::Current do
218
244
 
219
245
  it { should eql next_hour }
220
246
  end
247
+
248
+ context 'when there is not a summary' do
249
+ subject { current_no_summary.send(:next_hour) }
250
+
251
+ it { should be_an_instance_of String }
252
+
253
+ it { should eql summary_fail }
254
+ end
221
255
  end
222
256
 
223
257
  describe '.today' do
@@ -229,7 +263,7 @@ describe LitaForecast::Current do
229
263
  end
230
264
  end
231
265
 
232
- context 'when passed no args' do
266
+ context 'when there is a summary' do
233
267
  subject { current.send(:today) }
234
268
  let(:today) { 'hourly weather' }
235
269
 
@@ -237,6 +271,14 @@ describe LitaForecast::Current do
237
271
 
238
272
  it { should eql today }
239
273
  end
274
+
275
+ context 'when there is not a summary' do
276
+ subject { current_no_summary.send(:today) }
277
+
278
+ it { should be_an_instance_of String }
279
+
280
+ it { should eql summary_fail }
281
+ end
240
282
  end
241
283
 
242
284
  describe '.conditions' do
@@ -65,6 +65,141 @@ describe LitaForecast::Location do
65
65
  end
66
66
  end
67
67
 
68
+ describe '.city' do
69
+ context 'when given more than one arg' do
70
+ it 'should raise ArgumentError' do
71
+ expect do
72
+ @lfloc.send(:city, nil, nil)
73
+ end.to raise_error ArgumentError
74
+ end
75
+ end
76
+
77
+ context 'when given less than one arg' do
78
+ it 'should raise ArgumentError' do
79
+ expect do
80
+ @lfloc.send(:city)
81
+ end.to raise_error ArgumentError
82
+ end
83
+ end
84
+
85
+ context 'when given a location with a city and state' do
86
+ let(:location) { { city: 'San Francisco', state: 'CA' } }
87
+ subject { @lfloc.send(:city, location) }
88
+
89
+ it { should be_an_instance_of String }
90
+
91
+ it { should eql 'San Francisco' }
92
+ end
93
+
94
+ context 'when given a location with a city' do
95
+ let(:location) { { city: 'San Francisco' } }
96
+ subject { @lfloc.send(:city, location) }
97
+
98
+ it { should be_an_instance_of String }
99
+
100
+ it { should eql 'San Francisco' }
101
+ end
102
+
103
+ context 'when given a location without a city' do
104
+ let(:location) { { state: 'CA' } }
105
+ subject { @lfloc.send(:city, location) }
106
+
107
+ it { should be_an_instance_of String }
108
+
109
+ it { should eql '' }
110
+ end
111
+ end
112
+
113
+ describe '.state' do
114
+ context 'when given more than one arg' do
115
+ it 'should raise ArgumentError' do
116
+ expect do
117
+ subject.send(:state, nil, nil)
118
+ end.to raise_error ArgumentError
119
+ end
120
+ end
121
+
122
+ context 'when given less than one arg' do
123
+ it 'should raise ArgumentError' do
124
+ expect do
125
+ subject.send(:state)
126
+ end.to raise_error ArgumentError
127
+ end
128
+ end
129
+
130
+ context 'when given location with a city and a state' do
131
+ let(:location) { { city: 'San Francisco', state: 'CA' } }
132
+ subject { @lfloc.send(:state, location) }
133
+
134
+ it { should be_an_instance_of String }
135
+
136
+ it { should eql 'CA' }
137
+ end
138
+
139
+ context 'when given location with a state' do
140
+ let(:location) { { state: 'CA' } }
141
+ subject { @lfloc.send(:state, location) }
142
+
143
+ it { should be_an_instance_of String }
144
+
145
+ it { should eql 'CA' }
146
+ end
147
+
148
+ context 'when given location with only a city' do
149
+ let(:location) { { city: 'San Francisco' } }
150
+ subject { @lfloc.send(:state, location) }
151
+
152
+ it { should be_an_instance_of String }
153
+
154
+ it { should eql '' }
155
+ end
156
+ end
157
+
158
+ describe '.desc' do
159
+ context 'when given more than one arg' do
160
+ it 'should raise ArgumentError' do
161
+ expect do
162
+ @lfloc.send(:desc, nil, nil)
163
+ end.to raise_error ArgumentError
164
+ end
165
+ end
166
+
167
+ context 'when given less than one arg' do
168
+ it 'should raise Argument Error' do
169
+ expect do
170
+ @lfloc.send(:desc)
171
+ end.to raise_error ArgumentError
172
+ end
173
+ end
174
+
175
+ context 'when provided a location with a city and state' do
176
+ let(:loc_hash) { { city: 'San Francisco', state: 'CA' } }
177
+ subject { @lfloc.send(:desc, loc_hash) }
178
+
179
+ it { should be_an_instance_of String }
180
+
181
+ it { should eql 'San Francisco, CA'}
182
+ end
183
+
184
+ context 'when provided a location with only a state' do
185
+ let(:loc_hash) { { state: 'CA' } }
186
+ subject { @lfloc.send(:desc, loc_hash) }
187
+
188
+ it { should be_an_instance_of String }
189
+
190
+ it { should eql 'CA' }
191
+ end
192
+
193
+ context 'when provided a location with only a city' do
194
+ let(:loc_hash) { { city: 'San Francisco' } }
195
+ subject { @lfloc.send(:desc, loc_hash) }
196
+
197
+ it { should be_an_instance_of String }
198
+
199
+ it { should eql 'San Francisco' }
200
+ end
201
+ end
202
+
68
203
  describe '.find_location' do
69
204
  before do
70
205
  allow_any_instance_of(Geocoder).to receive(:search)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-forecast
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-31 00:00:00.000000000 Z
11
+ date: 2014-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 1.5.3
19
+ version: '1.5'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 1.5.3
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +174,7 @@ files:
174
174
  - ".rspec"
175
175
  - ".rubocop.yml"
176
176
  - ".travis.yml"
177
+ - CONTRIBUTING.md
177
178
  - Gemfile
178
179
  - LICENSE
179
180
  - README.md