class Village

Attributes

cell[RW]
district[RW]
province[RW]
sector[RW]
village[RW]

Public Class Methods

new(row) click to toggle source
# File lib/rwanda/village.rb, line 4
def initialize(row)
  @province,@district,@sector,@cell,@village=row['province'],row['district'],row['sector'],row['cell'],row['village']
end

Public Instance Methods

==(other) click to toggle source
# File lib/rwanda/village.rb, line 28
def ==(other)
  to_h == other.to_h
end
[](n) click to toggle source
# File lib/rwanda/village.rb, line 19
def [](n)
  raise "Division index #{n} out of range!  Permitted indices 0 (province) to 4 (village)" unless (0..4).include? n
  self.send(Rwanda::DIVISIONS[n])
end
match(str) click to toggle source
# File lib/rwanda/village.rb, line 10
def match(str)
  matches = []
  Rwanda::DIVISIONS.each do |div|
    if str.downcase == self.send(div).downcase
      matches.push div
    end
  end
  matches
end
to_h(*options) click to toggle source
# File lib/rwanda/village.rb, line 23
def to_h(*options)
  options = [:province, :district, :sector, :cell, :village] if options.empty?
  # this use of Array#to_h is only available from 2.1.0 onwards
  options.collect {|l| [ l, instance_variable_get("@#{l}") ] }.to_h
end
to_s() click to toggle source
# File lib/rwanda/village.rb, line 7
def to_s
  "#{@province}/#{@district}/#{@sector}/#{@cell}/#{@village}"
end