world_wrap 0.0.1 → 0.0.2
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 +4 -4
- data/lib/world_wrap.rb +10 -1
- data/spec/world_wrap_spec.rb +18 -0
- 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: b4744cef9fcdeafba9b922c41595350b20b3a948
|
4
|
+
data.tar.gz: 5d229574c1b305562c595a70bd87898e01aba21c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6d70e0a71cf984f19178e21fd6a88572eba00d418239b419a9bed295d70a7f60e513d4a71a062e736a4d2f48529dfda4b0885fb8a14aecbddba457ef14302c8
|
7
|
+
data.tar.gz: 0ab867da10e1ca9e037f85a6755383cfd1aacd1b5abf5da408b9329a2e23a4885fd3c405d46458713de7940b6f8f6542c8aa4b0b6dee646e9694b708b678619c
|
data/lib/world_wrap.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'country'
|
2
|
-
require '
|
2
|
+
require 'state'
|
3
3
|
require 'city'
|
4
4
|
module WorldWrap
|
5
5
|
def countries options = {}
|
@@ -9,12 +9,21 @@ module WorldWrap
|
|
9
9
|
def states options = {}
|
10
10
|
return "Please pass a country name or code" if options[:country].nil? || options[:country].empty?
|
11
11
|
country = options[:country].downcase
|
12
|
+
return "not a valid key" if is_invalid_key?(COUNTRIES, country)
|
13
|
+
return "Need to save data for #{country}" unless STATES.has_key?(country)
|
12
14
|
STATES[country]
|
13
15
|
end
|
14
16
|
|
15
17
|
def cities options = {}
|
16
18
|
return "Please pass a state name or code" if options[:state].nil? || options[:state].empty?
|
17
19
|
state = options[:state].downcase
|
20
|
+
# return "not a valid key" if is_invalid_key?(STATES, state) TODO
|
21
|
+
return "Need to store data for #{state} Or its not a state in the given list" unless CITIES.has_key?(state)
|
18
22
|
CITIES[state]
|
19
23
|
end
|
24
|
+
|
25
|
+
def is_invalid_key?(objects, value)
|
26
|
+
is_valid = objects.select{|object| object if [object[:name].downcase, object[:code].downcase].include?(value)}
|
27
|
+
is_valid.empty?
|
28
|
+
end
|
20
29
|
end
|
data/spec/world_wrap_spec.rb
CHANGED
@@ -26,6 +26,11 @@ describe WorldWrap do
|
|
26
26
|
actual = states({country: 'INDIA'})
|
27
27
|
expected.should == actual
|
28
28
|
end
|
29
|
+
it 'should return TODO message' do
|
30
|
+
expected = "Need to save data for af"
|
31
|
+
actual = states({country: 'AF'})
|
32
|
+
expected.should == actual
|
33
|
+
end
|
29
34
|
end
|
30
35
|
|
31
36
|
describe '#cities' do
|
@@ -41,4 +46,17 @@ describe WorldWrap do
|
|
41
46
|
expected.should == actual
|
42
47
|
end
|
43
48
|
end
|
49
|
+
|
50
|
+
describe '#is_valid_key?' do
|
51
|
+
it 'should return false when code or name not matched' do
|
52
|
+
expected = true
|
53
|
+
actual = is_invalid_key?(COUNTRIES, 'dilkhush')
|
54
|
+
expected.should == actual
|
55
|
+
end
|
56
|
+
it 'should return true when code or name matched' do
|
57
|
+
expected = false
|
58
|
+
actual = is_invalid_key?(COUNTRIES, 'in')
|
59
|
+
expected.should == actual
|
60
|
+
end
|
61
|
+
end
|
44
62
|
end
|