rwanda 0.3.3 → 0.4.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 +8 -8
- data/.gitignore +1 -0
- data/CHANGELOG.md +14 -0
- data/lib/rwanda/version.rb +1 -1
- data/lib/rwanda.rb +27 -11
- data/spec/rwanda_spec.rb +50 -28
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NGRkMTI3NzFiM2ZmMGNmYzQyZDAwZjUwNzdjYWJkZWM0NTAwNTAwZQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
MzEwNDc5MDViZDBjNmM4ZDlhYzQ5NzllM2Q4NzFjMGY0YWNkMTJmZg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjM2MTdiNzgyODQ2ZTE4ZjIzZmQyYmNmNTZjOWQ2MDViNGIyNDc5MDhjMGUw
|
10
|
+
MWY5MGE0NzU1NzZmZjFmNWFlZmVmOWQxYmNlN2VkNGEwNTVhOTUyNDM3N2U5
|
11
|
+
NDIwNmNiNmY2MmE2MGE1ZDI5NzRiNWRlZjVlZTcxOWM5YjJlMWQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MWZlZWVkZmRkMzQzM2FmNmZjYzc2YjU1ZjQzNDU3ZmQ5M2QwM2FjN2VhNzFl
|
14
|
+
NDUxZmQ4Njk1MjM4OGZlM2MyMjc1ZmRlM2M4YjNmODRmMzgyYjM2N2I0NzBm
|
15
|
+
ZDVlNDkzYzZjNmY3Y2I4ZDVhOTE3MzJiY2E4OTY5NmMyZmM5YmY=
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## 0.4.0
|
4
|
+
* Add case-insensitivity to all division lookups (#1)
|
5
|
+
* Add translation of province names between English and Kinyarwanda
|
6
|
+
|
7
|
+
## 0.3.3
|
8
|
+
* Fix relative path error
|
9
|
+
|
10
|
+
## 0.3.1
|
11
|
+
* Include cells and villages using data from MINALOC
|
12
|
+
|
13
|
+
## 0.1.0
|
14
|
+
* First release, covering only provinces, districts and sectors (data unavailable for cells and villages)
|
data/lib/rwanda/version.rb
CHANGED
data/lib/rwanda.rb
CHANGED
@@ -20,9 +20,7 @@ end
|
|
20
20
|
class Village
|
21
21
|
attr_accessor :province, :district, :sector, :cell, :village
|
22
22
|
|
23
|
-
#def initialize(province, district, sector, cell, village)
|
24
23
|
def initialize(row)
|
25
|
-
#@province,@district,@sector,@cell,@village=province,district,sector,cell,village
|
26
24
|
@province,@district,@sector,@cell,@village=row['province'],row['district'],row['sector'],row['cell'],row['village']
|
27
25
|
end
|
28
26
|
def to_s
|
@@ -47,9 +45,10 @@ class Rwanda
|
|
47
45
|
villages << Village.new(row)
|
48
46
|
end
|
49
47
|
end
|
48
|
+
|
50
49
|
# Singular Ofs ((
|
51
50
|
def province_of(district, rw=false)
|
52
|
-
village = @villages.select_first {|v| v.district == district}
|
51
|
+
village = @villages.select_first {|v| v.district.downcase == district.downcase}
|
53
52
|
if village
|
54
53
|
if rw then RW[village.province] else village.province end
|
55
54
|
else
|
@@ -57,24 +56,24 @@ class Rwanda
|
|
57
56
|
end
|
58
57
|
end
|
59
58
|
def district_of(sector)
|
60
|
-
village = @villages.select_first {|v| v.sector == sector}
|
59
|
+
village = @villages.select_first {|v| v.sector.downcase == sector.downcase}
|
61
60
|
village ? village.district : nil
|
62
61
|
end
|
63
62
|
# )) Plural Ofs ((
|
64
63
|
def districts_of(province)
|
65
|
-
districts = @villages.select {|v| v.province == province }.collect {|v| v.district}.uniq
|
64
|
+
districts = @villages.select {|v| v.province.downcase == province.downcase }.collect {|v| v.district}.uniq
|
66
65
|
#binding.pry
|
67
66
|
districts.empty? ? nil : districts
|
68
67
|
end
|
69
68
|
def sectors_of(district)
|
70
|
-
sectors = @villages.select {|v| v.district == district }.collect {|v| v.sector}.uniq
|
69
|
+
sectors = @villages.select {|v| v.district.downcase == district.downcase }.collect {|v| v.sector}.uniq
|
71
70
|
sectors.empty? ? nil : sectors
|
72
71
|
end
|
73
72
|
def cells_of(district, sector)
|
74
|
-
@villages.select {|v| v.district == district and v.sector == sector}.collect {|v| v.cell}.uniq
|
73
|
+
@villages.select {|v| v.district.downcase == district.downcase and v.sector.downcase == sector.downcase}.collect {|v| v.cell}.uniq
|
75
74
|
end
|
76
75
|
def villages_of(district, sector, cell)
|
77
|
-
@villages.select {|v| v.district == district and v.sector == sector and v.cell == cell}.collect {|v| v.village}
|
76
|
+
@villages.select {|v| v.district.downcase == district.downcase and v.sector.downcase == sector.downcase and v.cell.downcase == cell.downcase}.collect {|v| v.village}
|
78
77
|
end
|
79
78
|
# )) Lists ((
|
80
79
|
def provinces; @villages.collect{|v| v.province}.uniq; end
|
@@ -99,12 +98,13 @@ class Rwanda
|
|
99
98
|
@fms ||= FuzzyMatch.new(sectors)
|
100
99
|
@fms.find(sector)
|
101
100
|
end
|
102
|
-
|
101
|
+
|
102
|
+
# )) Testing ((
|
103
103
|
#def is_province?(province); @villages.any? {|v| v.province == province}; end
|
104
104
|
# is_division?
|
105
105
|
DIVISIONS.each do |division|
|
106
106
|
define_method("is_#{division}?") do |argument|
|
107
|
-
@villages.any? {|v| v.send(division) == argument}
|
107
|
+
@villages.any? {|v| v.send(division).downcase == argument.downcase}
|
108
108
|
end
|
109
109
|
end
|
110
110
|
def exist?(district, sector=false, cell=false, village=false)
|
@@ -113,10 +113,26 @@ class Rwanda
|
|
113
113
|
{district: district, sector: sector, cell: cell, village: village}.each_pair do |division_name,division|
|
114
114
|
#binding.pry
|
115
115
|
return true unless division
|
116
|
-
villages.select! {|v| v.send(division_name) == division}
|
116
|
+
villages.select! {|v| v.send(division_name).downcase == division.downcase}
|
117
117
|
return false if villages.empty?
|
118
118
|
end
|
119
119
|
true
|
120
120
|
end
|
121
|
+
|
122
|
+
# )) Translation ((
|
123
|
+
def translate(province)
|
124
|
+
kin = RW.find { |eng,kin| eng.downcase == province.downcase } # returns [key, val]
|
125
|
+
return kin[1] if kin
|
126
|
+
eng = RW.find { |eng,kin| kin.downcase == province.downcase }
|
127
|
+
return eng[0] if eng
|
128
|
+
nil
|
129
|
+
#if RW.has_key? province
|
130
|
+
# RW[province]
|
131
|
+
#elsif RW.has_value? province
|
132
|
+
# RW.key province
|
133
|
+
#else
|
134
|
+
# nil
|
135
|
+
#end
|
136
|
+
end
|
121
137
|
end
|
122
138
|
|
data/spec/rwanda_spec.rb
CHANGED
@@ -12,26 +12,20 @@ describe Rwanda do
|
|
12
12
|
# Singular Ofs
|
13
13
|
|
14
14
|
describe '.district_of' do
|
15
|
-
let(:input) { 'Jali' }
|
16
|
-
let(:output) { r.district_of(input) }
|
17
|
-
let(:wrong_in) { 'Foobar' }
|
18
|
-
let(:wrong_out) { r.district_of(wrong_in) }
|
19
|
-
|
20
15
|
it 'knows the distict of a sector' do
|
21
|
-
expect(
|
22
|
-
expect(
|
16
|
+
expect(r.district_of('Jali')).to eq 'Gasabo'
|
17
|
+
expect(r.district_of('jAlI')).to eq 'Gasabo'
|
18
|
+
|
19
|
+
expect(r.district_of('Foobar')).to eq nil
|
23
20
|
end
|
24
21
|
end
|
25
22
|
|
26
23
|
describe '.province_of' do
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
it 'knows the province of a district' do
|
33
|
-
expect(output).to eq 'Kigali City'
|
34
|
-
expect(wrong_out).to eq nil
|
24
|
+
it 'knows the province of a district, and can return it in Kinyarwanda' do
|
25
|
+
expect(r.province_of('gaSABO')).to eq 'Kigali City'
|
26
|
+
expect(r.province_of('Foobar')).to eq nil
|
27
|
+
expect(r.province_of('gaSABO', true)).to eq 'Umujyi wa Kigali'
|
28
|
+
expect(r.province_of('Foobar')).to eq nil
|
35
29
|
end
|
36
30
|
end
|
37
31
|
|
@@ -40,16 +34,15 @@ describe Rwanda do
|
|
40
34
|
describe '.districts_of' do
|
41
35
|
it 'knows all the districts of each province' do
|
42
36
|
expect(r.districts_of('Kigali City').sort).to eq ["Gasabo", "Kicukiro", "Nyarugenge"].sort
|
37
|
+
expect(r.districts_of('kigali city').sort).to eq ["Gasabo", "Kicukiro", "Nyarugenge"].sort
|
43
38
|
expect(r.districts_of('Foobar')).to eq nil
|
44
39
|
end
|
45
40
|
end
|
46
41
|
|
47
42
|
describe '.sectors_of' do
|
48
|
-
let(:input) { 'Gasabo' }
|
49
|
-
let(:output) { r.sectors_of(input) }
|
50
43
|
|
51
44
|
it 'knows all the sectors of a district' do
|
52
|
-
expect(
|
45
|
+
expect(r.sectors_of('GasABO').sort).to eq [ 'Bumbogo', 'Gatsata', 'Gikomero', 'Gisozi', 'Jabana', 'Jali', 'Kacyiru', 'Kimihurura', 'Kimironko', 'Kinyinya', 'Ndera', 'Nduba', 'Remera', 'Rusororo', 'Rutunga' ].sort
|
53
46
|
expect(r.sectors_of('Foobar')).to eq nil
|
54
47
|
end
|
55
48
|
end
|
@@ -60,22 +53,22 @@ describe Rwanda do
|
|
60
53
|
it 'knows all the cells of a sector' do
|
61
54
|
# Nyagatare,Mimuri,Mahoro,Rubumba
|
62
55
|
expect(r.cells_of('Nyagatare', 'Mimuri')).to eq ['Bibare', 'Gakoma', 'Mahoro', 'Mimuri', 'Rugari']
|
56
|
+
expect(r.cells_of('nyagatare', 'MIMURI')).to eq ['Bibare', 'Gakoma', 'Mahoro', 'Mimuri', 'Rugari']
|
63
57
|
end
|
64
58
|
end
|
65
59
|
|
66
60
|
describe '.villages_of' do
|
67
61
|
it 'knows all the villages of a cell' do
|
68
62
|
expect(r.villages_of('Ruhango', 'Ruhango', 'Gikoma')).to eq ['Gatengeri', 'Gikumba', 'Karama', 'Murambi', 'Nangurugomo', 'Nyarusange', 'Rebero', 'Rubiha', 'Rurembo', 'Ryabonyinka', 'Wimana']
|
63
|
+
expect(r.villages_of('RuhANgo', 'RUHANGO', 'GIKOMA')).to eq ['Gatengeri', 'Gikumba', 'Karama', 'Murambi', 'Nangurugomo', 'Nyarusange', 'Rebero', 'Rubiha', 'Rurembo', 'Ryabonyinka', 'Wimana']
|
69
64
|
end
|
70
65
|
end
|
71
66
|
|
72
67
|
# Lists
|
73
68
|
|
74
69
|
describe '.provinces' do
|
75
|
-
let(:output) { r.provinces }
|
76
|
-
|
77
70
|
it 'can list the provinces of Rwanda' do
|
78
|
-
expect(
|
71
|
+
expect(r.provinces.sort).to eq ["Kigali City", "Western Province", "Northern Province", "Southern Province", "Eastern Province"].sort
|
79
72
|
end
|
80
73
|
end
|
81
74
|
|
@@ -88,12 +81,8 @@ describe Rwanda do
|
|
88
81
|
end
|
89
82
|
|
90
83
|
describe '.sectors' do
|
91
|
-
#let (:output) { r.sectors }
|
92
|
-
|
93
84
|
it 'can list the sectors of Rwanda' do
|
94
85
|
expect(r.sectors.count).to eq 416
|
95
|
-
#expect(r.sectors.sort).to eq SECTORS
|
96
|
-
#expect(SECTORS - r.sectors).to eq []
|
97
86
|
r.sectors.each_with_index do |s,i|
|
98
87
|
expect(s).to eq SECTORS[i]
|
99
88
|
end
|
@@ -105,6 +94,7 @@ describe Rwanda do
|
|
105
94
|
describe '.[division]_like' do
|
106
95
|
it 'can offer suggestions for mis-typed provinces' do
|
107
96
|
expect(r.province_like('Westrun Provinc')).to eq 'Western Province'
|
97
|
+
expect(r.province_like('westrun provinc')).to eq 'Western Province'
|
108
98
|
end
|
109
99
|
it 'can offer suggestions for mis-typed districts' do
|
110
100
|
expect(r.district_like('Gasabu')).to eq 'Gasabo'
|
@@ -117,7 +107,7 @@ describe Rwanda do
|
|
117
107
|
# Testing
|
118
108
|
|
119
109
|
describe '.is_[division]?' do
|
120
|
-
it 'knows whether a division exists' do
|
110
|
+
it 'knows whether a division exists, even if the case is wrong' do
|
121
111
|
expect(r.is_district? 'Karongi').to eq true
|
122
112
|
expect(r.is_sector? 'Gashari').to eq true
|
123
113
|
expect(r.is_cell? 'Musasa').to eq true
|
@@ -126,16 +116,48 @@ describe Rwanda do
|
|
126
116
|
expect(r.is_sector? 'Gashariii').to eq false
|
127
117
|
expect(r.is_cell? 'Musasasasasa').to eq false
|
128
118
|
expect(r.is_village? 'Kaduhahaha').to eq false
|
119
|
+
|
120
|
+
expect(r.is_district? 'karongi').to eq true
|
121
|
+
expect(r.is_sector? 'gashari').to eq true
|
122
|
+
expect(r.is_cell? 'musasa').to eq true
|
123
|
+
expect(r.is_village? 'kaduha').to eq true
|
124
|
+
expect(r.is_district? 'karoooongi').to eq false
|
125
|
+
expect(r.is_sector? 'gashariii').to eq false
|
126
|
+
expect(r.is_cell? 'musasasasasa').to eq false
|
127
|
+
expect(r.is_village? 'kaduhahaha').to eq false
|
129
128
|
end
|
130
129
|
end
|
131
130
|
|
132
|
-
describe '.
|
133
|
-
it 'knows whether a chain of divisions is legitimate' do
|
131
|
+
describe '.exist?' do
|
132
|
+
it 'knows whether a chain of divisions is legitimate, case insensitively' do
|
134
133
|
expect(r.exist?('Karongi','Bwishyura','Kiniha','Nyarurembo')).to eq true
|
135
134
|
expect(r.exist?('Karongi','Bwishyura','Nyarurembo')).to eq false
|
136
135
|
expect(r.exist?('Karongi')).to eq true
|
136
|
+
|
137
|
+
expect(r.exist?('karongi','bwishyura','kiniha','nyarurembo')).to eq true
|
138
|
+
expect(r.exist?('karongi','bwishyura','nyarurembo')).to eq false
|
139
|
+
expect(r.exist?('karongi')).to eq true
|
137
140
|
end
|
138
141
|
end
|
142
|
+
|
143
|
+
describe '.translate' do
|
144
|
+
it 'can translate a province from English to Kinyarwanda' do
|
145
|
+
expect(r.translate('Northern Province')).to eq 'Amajyaruguru'
|
146
|
+
expect(r.translate('Southern Province')).to eq 'Amajyepfo'
|
147
|
+
expect(r.translate('eastern province')).to eq 'Iburasirazuba'
|
148
|
+
expect(r.translate('WESTERN PROVINCE')).to eq 'Iburengerazuba'
|
149
|
+
expect(r.translate('Kigali City')).to eq 'Umujyi wa Kigali'
|
150
|
+
expect(r.translate('foobar')).to eq nil
|
151
|
+
end
|
152
|
+
it 'can translate a province from Kinyarwanda to English' do
|
153
|
+
expect(r.translate('Amajyaruguru')).to eq 'Northern Province'
|
154
|
+
expect(r.translate('AmajyePFO')).to eq 'Southern Province'
|
155
|
+
expect(r.translate('Iburasirazuba')).to eq 'Eastern Province'
|
156
|
+
expect(r.translate('Iburengerazuba')).to eq 'Western Province'
|
157
|
+
expect(r.translate('umujyi wa kigali')).to eq 'Kigali City'
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
139
161
|
#describe '.is_in?' do
|
140
162
|
# it 'knows whether a smaller division is inside a larger division' do
|
141
163
|
# 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.4.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-
|
11
|
+
date: 2015-04-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -88,6 +88,7 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- .gitignore
|
91
|
+
- CHANGELOG.md
|
91
92
|
- Gemfile
|
92
93
|
- LICENSE.txt
|
93
94
|
- README.md
|