rwanda 0.4.0 → 0.5.3
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 +8 -8
- data/CHANGELOG.md +7 -0
- data/README.md +8 -0
- data/lib/rwanda.rb +76 -3
- data/lib/rwanda/version.rb +1 -1
- data/spec/rwanda_spec.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZDJmYjJlYmJhNTc1MmEyNTg0ODRiZDk5NjFiODFhNmIzNGNlN2IwZg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTNhM2I3NDQ4ZDVkYTc5MzYwNGU4ODc0MWM2N2YyYjJhYTEwZDJlYQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzhkYWY4NjNkMGNlZmZlMDFhNzk5NWE3MjRhZWI1MjE0NjczM2ZiZTlhMDY4
|
10
|
+
OTg2ZTMzOTk1YjRmNjU0NjQ3YzY1MGE0OTQ0NzM0ZGZlZGQ2NzI1YzIwMGRl
|
11
|
+
ZDA2NWM5Yjg3YjliYTExYzlhNWY2MjRlNzQ4NWU0ZGMyN2NlNTc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MzEyN2NiNWQwOTk4NTExMmQ5YzRmYzU1MDlhOGJiZDdiNTYwMzJmOTA2NWIy
|
14
|
+
MzkyZmU3MmE4NTgyYjdhNWZlNzQ0M2QwMGMzMDNhOGE0NTg4MzY2OWU4ZjQ1
|
15
|
+
ZThjMzdiMWU3NzZkODEyZjNiZGMxYzQ0OWM1ODBiZGY5Njk2NmQ=
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 0.5.2
|
4
|
+
* Fix serious bug in .where_is? that gave incorrect information
|
5
|
+
|
6
|
+
## 0.5.0
|
7
|
+
* Add .where_is? to enable fast general queries of the dataset
|
8
|
+
* allow .exists? as a synonym of .exist?
|
9
|
+
|
3
10
|
## 0.4.0
|
4
11
|
* Add case-insensitivity to all division lookups (#1)
|
5
12
|
* Add translation of province names between English and Kinyarwanda
|
data/README.md
CHANGED
@@ -18,10 +18,17 @@ Or install it yourself as:
|
|
18
18
|
|
19
19
|
$ gem install rwanda
|
20
20
|
|
21
|
+
Then you can try it on the command line:
|
22
|
+
|
23
|
+
$ pry
|
24
|
+
> gem 'rwanda'
|
25
|
+
> require 'rwanda'
|
26
|
+
|
21
27
|
## Usage
|
22
28
|
|
23
29
|
```ruby
|
24
30
|
rw = Rwanda.new
|
31
|
+
rw.where_is? 'Gasabo'
|
25
32
|
rw.provinces
|
26
33
|
rw.sectors_of 'Gasabo'
|
27
34
|
rw.district_of 'Giheke'
|
@@ -60,6 +67,7 @@ If you are not familiar with this data set, it's worth noting the following feat
|
|
60
67
|
* sector, cell and village names are often repeated: two sectors in different districts may have the same name, or a sector, cell and village may all have the same name
|
61
68
|
* cells and villages may be named after the sectors and cells that they are in
|
62
69
|
* at the cell or village level, there may be multiple villages with the same name, differentiated by a number (in roman numerals) e.g. Matimba cell has seven "Umudugudu Wa"s
|
70
|
+
* you might find where_is? helpful for inspecting ambiguity: it lists all divisions at all levels that share the name you give it (try `rw.where_is? 'Gatsibo'`)
|
63
71
|
|
64
72
|
## Contributing
|
65
73
|
|
data/lib/rwanda.rb
CHANGED
@@ -26,6 +26,19 @@ class Village
|
|
26
26
|
def to_s
|
27
27
|
"#{@province}/#{@district}/#{@sector}/#{@cell}/#{@village}"
|
28
28
|
end
|
29
|
+
def match(str)
|
30
|
+
matches = []
|
31
|
+
Rwanda::DIVISIONS.each do |div|
|
32
|
+
if str.downcase == self.send(div).downcase
|
33
|
+
matches.push div
|
34
|
+
end
|
35
|
+
end
|
36
|
+
matches
|
37
|
+
end
|
38
|
+
def [](n)
|
39
|
+
raise "Division index #{n} out of range! Permitted indices 0 (province) to 4 (village)" unless (0..4).include? n
|
40
|
+
self.send(Rwanda::DIVISIONS[n])
|
41
|
+
end
|
29
42
|
end
|
30
43
|
|
31
44
|
class Rwanda
|
@@ -74,7 +87,23 @@ class Rwanda
|
|
74
87
|
end
|
75
88
|
def villages_of(district, sector, cell)
|
76
89
|
@villages.select {|v| v.district.downcase == district.downcase and v.sector.downcase == sector.downcase and v.cell.downcase == cell.downcase}.collect {|v| v.village}
|
77
|
-
end
|
90
|
+
end
|
91
|
+
def subdivisions_of(arr)
|
92
|
+
case arr.length
|
93
|
+
when 1
|
94
|
+
sectors_of *arr
|
95
|
+
when 2
|
96
|
+
cells_of *arr
|
97
|
+
when 3
|
98
|
+
villages_of *arr
|
99
|
+
else
|
100
|
+
raise "subdivisions_of requires an array of between 1 and 3 elements (do NOT include a province): received #{arr}"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
# )) Calleds ((
|
104
|
+
#def districts_called(district)
|
105
|
+
# @villages
|
106
|
+
#end
|
78
107
|
# )) Lists ((
|
79
108
|
def provinces; @villages.collect{|v| v.province}.uniq; end
|
80
109
|
def districts; @villages.collect{|v| v.district}.uniq; end
|
@@ -107,9 +136,9 @@ class Rwanda
|
|
107
136
|
@villages.any? {|v| v.send(division).downcase == argument.downcase}
|
108
137
|
end
|
109
138
|
end
|
110
|
-
def exist?(district, sector=false, cell=false, village=false)
|
139
|
+
def exist?(district=false, sector=false, cell=false, village=false)
|
111
140
|
villages = @villages.dup
|
112
|
-
return
|
141
|
+
return nil unless district
|
113
142
|
{district: district, sector: sector, cell: cell, village: village}.each_pair do |division_name,division|
|
114
143
|
#binding.pry
|
115
144
|
return true unless division
|
@@ -118,6 +147,7 @@ class Rwanda
|
|
118
147
|
end
|
119
148
|
true
|
120
149
|
end
|
150
|
+
def exists?(*p); exist?(*p); end
|
121
151
|
|
122
152
|
# )) Translation ((
|
123
153
|
def translate(province)
|
@@ -134,5 +164,48 @@ class Rwanda
|
|
134
164
|
# nil
|
135
165
|
#end
|
136
166
|
end
|
167
|
+
|
168
|
+
# )) Where is...? ((
|
169
|
+
def where_is?(division)
|
170
|
+
matching = { province: [], district: [], sector: [], cell: [], village: [] }
|
171
|
+
lines = []
|
172
|
+
@villages.each do |village|
|
173
|
+
matches = village.match(division)
|
174
|
+
unless matches.empty?
|
175
|
+
matches.each do |div|
|
176
|
+
matching[div].push village
|
177
|
+
# convert villages into lines
|
178
|
+
new_line = " #{village.send(div)} is a #{div}#{' in' unless div==:province}"
|
179
|
+
unless div == :province
|
180
|
+
(0...Rwanda::DIVISIONS.index(div)).to_a.reverse.each do |n|
|
181
|
+
new_line << " #{village[n]}#{' '+Rwanda::DIVISIONS[n].to_s.capitalize+',' unless n==0}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
lines << new_line
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
lines.uniq!
|
189
|
+
output = ''
|
190
|
+
|
191
|
+
# summary line
|
192
|
+
if lines.empty?
|
193
|
+
output += "Rwanda has no divisions called #{division.capitalize}\n"
|
194
|
+
else
|
195
|
+
output += 'Rwanda has'
|
196
|
+
n = []
|
197
|
+
comma = ''
|
198
|
+
(0..3).each do |i|
|
199
|
+
n = lines.count { |l| l.count(',') == i }
|
200
|
+
output << "#{comma} #{i == 3 ? 'and ' : ''}#{n} #{Rwanda::DIVISIONS[i+1]}#{n == 1 ? '' : 's'}"
|
201
|
+
comma = ','
|
202
|
+
end
|
203
|
+
output << " called #{division.capitalize}:\n"
|
204
|
+
end
|
205
|
+
|
206
|
+
# detail
|
207
|
+
lines.each { |line| output << line << "\n" }
|
208
|
+
puts output
|
209
|
+
end
|
137
210
|
end
|
138
211
|
|
data/lib/rwanda/version.rb
CHANGED
data/spec/rwanda_spec.rb
CHANGED
@@ -64,6 +64,13 @@ describe Rwanda do
|
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
67
|
+
describe '.subdivisions_of' do
|
68
|
+
it 'knows the sub-divisions of a district, sector or cell' do
|
69
|
+
expect(r.subdivisions_of(['Ruhango', 'Ruhango', 'Gikoma'])).to eq ['Gatengeri', 'Gikumba', 'Karama', 'Murambi', 'Nangurugomo', 'Nyarusange', 'Rebero', 'Rubiha', 'Rurembo', 'Ryabonyinka', 'Wimana']
|
70
|
+
expect(r.subdivisions_of(['RuhANgo', 'RUHANGO', 'GIKOMA'])).to eq ['Gatengeri', 'Gikumba', 'Karama', 'Murambi', 'Nangurugomo', 'Nyarusange', 'Rebero', 'Rubiha', 'Rurembo', 'Ryabonyinka', 'Wimana']
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
67
74
|
# Lists
|
68
75
|
|
69
76
|
describe '.provinces' do
|
@@ -137,6 +144,10 @@ describe Rwanda do
|
|
137
144
|
expect(r.exist?('karongi','bwishyura','kiniha','nyarurembo')).to eq true
|
138
145
|
expect(r.exist?('karongi','bwishyura','nyarurembo')).to eq false
|
139
146
|
expect(r.exist?('karongi')).to eq true
|
147
|
+
|
148
|
+
# .exists? is an acceptable synonym
|
149
|
+
expect(r.exists?('Karongi','Bwishyura','Kiniha','Nyarurembo')).to eq true
|
150
|
+
expect(r.exists?('karongi')).to eq true
|
140
151
|
end
|
141
152
|
end
|
142
153
|
|
@@ -157,7 +168,16 @@ describe Rwanda do
|
|
157
168
|
expect(r.translate('umujyi wa kigali')).to eq 'Kigali City'
|
158
169
|
end
|
159
170
|
end
|
160
|
-
|
171
|
+
|
172
|
+
describe '.where_is?' do
|
173
|
+
it 'can list all of the divisions by a certain name' do
|
174
|
+
expect(STDOUT).to receive(:puts).with("Rwanda has 0 districts, 1 sector, 1 cell, and 1 village called Ndego:\n Ndego is a sector in Kayonza District, Eastern Province\n Ndego is a cell in Karama Sector, Nyagatare District, Eastern Province\n Ndego is a village in Ndego Cell, Karama Sector, Nyagatare District, Eastern Province\n")
|
175
|
+
r.where_is? 'ndego'
|
176
|
+
expect(STDOUT).to receive(:puts).with("Rwanda has no divisions called Foobar\n")
|
177
|
+
r.where_is? 'Foobar'
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
161
181
|
#describe '.is_in?' do
|
162
182
|
# it 'knows whether a smaller division is inside a larger division' do
|
163
183
|
# expect(r.is_in?('Karongi','Gashari')).to eq true
|
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.
|
4
|
+
version: 0.5.3
|
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-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|