rwanda 0.7.2 → 0.8.0

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: 9a00b6d65c44a7f85e5a71b0dddb5841bbf92659
4
- data.tar.gz: c9b1891159f33205c1f522834549ac970db920b7
3
+ metadata.gz: a8fcd2d987c04671d739e62c9e910669046860b9
4
+ data.tar.gz: 89fb5f38046645dbc3197dd67024a24a4cf151d8
5
5
  SHA512:
6
- metadata.gz: 423d6dc096c803a290c1e485a88d4ec086d93de02c843a119432b755f661bd288a8cd34061b6f104ba53b2efa210a38bf10f9f02ac0607f5a69910d76f99d472
7
- data.tar.gz: 829894ae447be99a0c6123e955db6c071866333ae7a9cd5043ce582cb2f78009ba4d0c99aee3cf53ac7214ba4b0f8a1b54d27e0e8e90a9cc5e6bef4782d5aa57
6
+ metadata.gz: 557b747e34beed787334854a043d9996afb91fa641807fafc3c7da04927fb88d3f717dadc31b8cf5cc8d2cd214212c0edc64cd9318837803130a9df06e47d6ae
7
+ data.tar.gz: b8ee160322159c11117afdcabd5bf248f3b619d5c37f0982ae9670847d9285d40fabc7f92a9ff2490020faa0c0a26543bfca03d3c3341e9434dd7c95ec3111cf
data/.gitignore CHANGED
@@ -14,3 +14,4 @@
14
14
  mkmf.log
15
15
  kigali-sez.txt
16
16
  .ruby-version
17
+ .~lock*
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+
5
+ * Fix .district_of when sector belongs to multiple districts (#2)
6
+
3
7
  ## 0.7.2
4
8
 
5
9
  * Add Coveralls and Travis CI
data/README.md CHANGED
@@ -34,9 +34,9 @@ Then you can try it on the command line:
34
34
  ## Usage
35
35
 
36
36
  ```ruby
37
- [2] pry(main)> rw=Rwanda.instance
37
+ pry(main)> rw=Rwanda.instance
38
38
  => #<Rwanda:0x007f00ea48cf28 ... >
39
- [3] pry(main)> rw.where_is? 'Gasabo'
39
+ pry(main)> rw.where_is? 'Gasabo'
40
40
  Rwanda has 1 district, 0 sectors, 1 cell, and 8 villages called Gasabo:
41
41
  Gasabo is a village in Kimaranzara Cell, Rilima Sector, Bugesera District, Eastern Province
42
42
  Gasabo is a village in Butiruka Cell, Remera Sector, Gatsibo District, Eastern Province
@@ -49,27 +49,29 @@ Rwanda has 1 district, 0 sectors, 1 cell, and 8 villages called Gasabo:
49
49
  Gasabo is a village in Kabeza Cell, Kanombe Sector, Kicukiro District, Kigali City
50
50
  Gasabo is a village in Kabuguru II Cell, Rwezamenyo Sector, Nyarugenge District, Kigali City
51
51
  => nil
52
- [4] pry(main)> rw.provinces
52
+ pry(main)> rw.provinces
53
53
  => ["Eastern Province", "Kigali City", "Northern Province", "Southern Province", "Western Province"]
54
- [5] pry(main)> rw.sectors_of 'Gasabo'
54
+ pry(main)> rw.sectors_of 'Gasabo'
55
55
  => ["Bumbogo", "Gatsata", "Gikomero", "Gisozi", "Jabana", "Jali", "Kacyiru", "Kimihurura", "Kimironko", "Kinyinya", "Ndera", "Nduba", "Remera", "Rusororo", "Rutunga"]
56
- [6] pry(main)> rw.district_of 'Giheke'
56
+ pry(main)> rw.district_of 'Giheke'
57
57
  => "Rusizi"
58
- [7] pry(main)> rw.sector_like 'Rukuma'
58
+ pry(main)> rw.district_of 'Busasamana' # returns array if multiple
59
+ => ["Nyanza", "Rubavu"]
60
+ pry(main)> rw.sector_like 'Rukuma'
59
61
  RuntimeError: can't modify frozen #<Class:#<Rwanda:0x007f00ea48cf28>>
60
62
  from /home/slack/vendor/bundle/gems/rwanda-0.7.1/lib/rwanda.rb:87:in `sectors'
61
- [8] pry(main)> rw.is_district? 'Karongi'
63
+ pry(main)> rw.is_district? 'Karongi'
62
64
  => true
63
- [9] pry(main)> rw.is_sector? 'Gashari'
65
+ pry(main)> rw.is_sector? 'Gashari'
64
66
  => true
65
- [10] pry(main)> rw.is_cell? 'Musasa'
67
+ pry(main)> rw.is_cell? 'Musasa'
66
68
  => true
67
- [11] pry(main)> rw.is_village? 'Kaduha'
69
+ pry(main)> rw.is_village? 'Kaduha'
68
70
  => true
69
- [12] pry(main)> # Rwanda#exist?(district, sector, cell, village)
70
- [13] pry(main)> rw.exist?('Karongi','Bwishyura','Kiniha','Nyarurembo')
71
+ pry(main)> # Rwanda#exist?(district, sector, cell, village)
72
+ pry(main)> rw.exist?('Karongi','Bwishyura','Kiniha','Nyarurembo')
71
73
  => true
72
- [14] pry(main)> rw.exist?('Karongi','Bwishyura','Nyarurembo')
74
+ pry(main)> rw.exist?('Karongi','Bwishyura','Nyarurembo')
73
75
  => false
74
76
  ```
75
77
 
data/lib/rwanda.rb CHANGED
@@ -42,8 +42,15 @@ class Rwanda
42
42
  end
43
43
  end
44
44
  def district_of(sector)
45
- village = @villages.select_first {|v| v.sector.downcase == sector.downcase}
46
- village ? village.district : nil
45
+ villages = @villages.select {|v| v.sector.downcase == sector.downcase}.collect {|v| { sector: v.sector, district: v.district } }.uniq
46
+ case villages.length
47
+ when 0
48
+ nil
49
+ when 1
50
+ villages[0][:district]
51
+ else
52
+ villages.collect {|v| v[:district] }.sort
53
+ end
47
54
  end
48
55
  # )) Plural Ofs ((
49
56
  def districts_of(province)
@@ -1,3 +1,3 @@
1
1
  class Rwanda
2
- VERSION = "0.7.2"
2
+ VERSION = "0.8.0"
3
3
  end
data/spec/rwanda_spec.rb CHANGED
@@ -7,10 +7,16 @@ describe Rwanda do
7
7
  # Singular Ofs
8
8
 
9
9
  describe '.district_of' do
10
- it 'knows the distict of a sector' do
10
+ it 'knows the distict(s) of a sector' do
11
+ # Unfortunately, there are multiple sectors with the same name in different districts
12
+ # so this cannot give a unique response all of the time
13
+ # e.g. Busasamana in Nyanza and Rubavu
11
14
  expect(r.district_of('Jali')).to eq 'Gasabo'
12
15
  expect(r.district_of('jAlI')).to eq 'Gasabo'
13
16
 
17
+ # Returns districts in alphabetical order
18
+ expect(r.district_of('Busasamana')).to eq [ 'Nyanza', 'Rubavu' ].sort
19
+
14
20
  expect(r.district_of('Foobar')).to eq nil
15
21
  end
16
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rwanda
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.2
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Hetherington
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-03 00:00:00.000000000 Z
11
+ date: 2015-06-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler