Class: Rwanda
- Inherits:
-
Object
- Object
- Rwanda
- Defined in:
- lib/rwanda.rb,
lib/rwanda/version.rb
Constant Summary collapse
- DIVISIONS =
[:province,:district,:sector,:cell,:village]
- RW =
{ 'Northern Province' => 'Amajyaruguru', 'Southern Province' => 'Amajyepfo', 'Eastern Province' => 'Iburasirazuba', 'Western Province' => 'Iburengerazuba', 'Kigali City' => 'Umujyi wa Kigali' }
- VERSION =
"0.3.3"
Instance Attribute Summary collapse
-
#villages ⇒ Object
Returns the value of attribute villages.
Instance Method Summary collapse
- #cells_of(district, sector) ⇒ Object
- #district_like(district) ⇒ Object
- #district_of(sector) ⇒ Object
- #districts ⇒ Object
-
#districts_of(province) ⇒ Object
)) Plural Ofs ((.
- #exist?(district, sector = false, cell = false, village = false) ⇒ Boolean
-
#initialize ⇒ Rwanda
constructor
A new instance of Rwanda.
-
#province_like(province) ⇒ Object
)) Matching ((.
-
#province_of(district, rw = false) ⇒ Object
Singular Ofs ((.
-
#provinces ⇒ Object
)) Lists ((.
- #sector_like(sector) ⇒ Object
-
#sectors ⇒ Object
already introduces ambiguity from sectors down: 37 districts are duplicate names.
- #sectors_of(district) ⇒ Object
- #villages_of(district, sector, cell) ⇒ Object
Constructor Details
#initialize ⇒ Rwanda
Returns a new instance of Rwanda.
44 45 46 47 48 49 |
# File 'lib/rwanda.rb', line 44 def initialize @villages = [] CSV.foreach(DATA, headers: :first_row) do |row| villages << Village.new(row) end end |
Instance Attribute Details
#villages ⇒ Object
Returns the value of attribute villages.
34 35 36 |
# File 'lib/rwanda.rb', line 34 def villages @villages end |
Instance Method Details
#cells_of(district, sector) ⇒ Object
73 74 75 |
# File 'lib/rwanda.rb', line 73 def cells_of(district, sector) @villages.select {|v| v.district == district and v.sector == sector}.collect {|v| v.cell}.uniq end |
#district_like(district) ⇒ Object
93 94 95 96 |
# File 'lib/rwanda.rb', line 93 def district_like(district) @fmd ||= FuzzyMatch.new(districts) @fmd.find(district) end |
#district_of(sector) ⇒ Object
59 60 61 62 |
# File 'lib/rwanda.rb', line 59 def district_of(sector) village = @villages.select_first {|v| v.sector == sector} village ? village.district : nil end |
#districts ⇒ Object
81 |
# File 'lib/rwanda.rb', line 81 def districts; @villages.collect{|v| v.district}.uniq; end |
#districts_of(province) ⇒ Object
)) Plural Ofs ((
64 65 66 67 68 |
# File 'lib/rwanda.rb', line 64 def districts_of(province) districts = @villages.select {|v| v.province == province }.collect {|v| v.district}.uniq #binding.pry districts.empty? ? nil : districts end |
#exist?(district, sector = false, cell = false, village = false) ⇒ Boolean
110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rwanda.rb', line 110 def exist?(district, sector=false, cell=false, village=false) villages = @villages.dup return false unless district {district: district, sector: sector, cell: cell, village: village}.each_pair do |division_name,division| #binding.pry return true unless division villages.select! {|v| v.send(division_name) == division} return false if villages.empty? end true end |
#province_like(province) ⇒ Object
)) Matching ((
89 90 91 92 |
# File 'lib/rwanda.rb', line 89 def province_like(province) @fmp ||= FuzzyMatch.new(provinces) @fmp.find(province) end |
#province_of(district, rw = false) ⇒ Object
Singular Ofs ((
51 52 53 54 55 56 57 58 |
# File 'lib/rwanda.rb', line 51 def province_of(district, rw=false) village = @villages.select_first {|v| v.district == district} if village if rw then RW[village.province] else village.province end else nil end end |
#provinces ⇒ Object
)) Lists ((
80 |
# File 'lib/rwanda.rb', line 80 def provinces; @villages.collect{|v| v.province}.uniq; end |
#sector_like(sector) ⇒ Object
97 98 99 100 101 |
# File 'lib/rwanda.rb', line 97 def sector_like(sector) # Already problematic here: there are identical sector names @fms ||= FuzzyMatch.new(sectors) @fms.find(sector) end |
#sectors ⇒ Object
already introduces ambiguity from sectors down: 37 districts are duplicate names
83 84 85 86 |
# File 'lib/rwanda.rb', line 83 def sectors @sectors ||= @villages.collect {|v| [v.district, v.sector] }.uniq.collect {|ds| ds[1]}.sort #@villages.collect{|v| v.sector}.uniq end |
#sectors_of(district) ⇒ Object
69 70 71 72 |
# File 'lib/rwanda.rb', line 69 def sectors_of(district) sectors = @villages.select {|v| v.district == district }.collect {|v| v.sector}.uniq sectors.empty? ? nil : sectors end |
#villages_of(district, sector, cell) ⇒ Object
76 77 78 |
# File 'lib/rwanda.rb', line 76 def villages_of(district, sector, cell) @villages.select {|v| v.district == district and v.sector == sector and v.cell == cell}.collect {|v| v.village} end |