world_wrap 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dc747a45c346b26d2c2b01b3923be985fb9b86f6
4
- data.tar.gz: b287bcdc976c8301901b57813e914a104e620b0e
3
+ metadata.gz: b4744cef9fcdeafba9b922c41595350b20b3a948
4
+ data.tar.gz: 5d229574c1b305562c595a70bd87898e01aba21c
5
5
  SHA512:
6
- metadata.gz: 649f56dfc14df7a0b2a2e8cbab35dbcddad3f9b6b7a218f8063ba3d6862a26fe37f9fc5fa47d2087c57f7dca82e9577e58316410082bcca50d99d0f304708b46
7
- data.tar.gz: 91aa3510270d3ec1576ddb439ac583de3c3146bd23276f61bcbe1fd6bfdae607f495a338442c0d00762296addf26bc03b33ed4ec676fe74ff01f4c0cda4b3e25
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 'states'
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
@@ -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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: world_wrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dilkhush Soni