class NlApi::HistoricMunicipality

Attributes

filename[W]
code[R]
code_after_merge[R]
name[R]

Public Class Methods

all() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 46
def all
  @all ||= read_csv
end
each(&block) click to toggle source
# File lib/nl_api/historic_municipality.rb, line 50
def each(&block)
  all.each(&block)
  self
end
filename() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 28
def filename
  @filename ||= '../../data/BAG_gemeententabel.csv'
end
find_all_by(where) click to toggle source
# File lib/nl_api/historic_municipality.rb, line 62
def find_all_by(where)
  field = where.keys.first
  value = where.values.first

  find_all{ |i| i.send(field.to_sym) == value }
end
find_by(where) click to toggle source
# File lib/nl_api/historic_municipality.rb, line 55
def find_by(where)
  field = where.keys.first
  value = where.values.first

  find{ |i| i.send(field.to_sym) == value }
end
new(attributes) click to toggle source
# File lib/nl_api/historic_municipality.rb, line 4
def initialize(attributes)
  @code = attributes[:code]
  @name = attributes[:name]
  @code_after_merge = attributes[:code_after_merge]
end
path() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 32
def path
  File.join(File.dirname(File.expand_path(__FILE__)), filename)
end
read_csv() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 36
def read_csv
  @store ||= CSV.read(path, headers: true, col_sep: ',').map do |line|
    NlApi::HistoricMunicipality.new(
      code: line[0].to_i,
      name: line[1],
      code_after_merge: line[2].to_i
    )
  end
end

Public Instance Methods

has_merged?() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 18
def has_merged?
  !!code_after_merge
end
municipality_after_merge() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 14
def municipality_after_merge
  has_merged? ? NlApi::Municipality.find_by(code: code_after_merge) : nil
end
province() click to toggle source
# File lib/nl_api/historic_municipality.rb, line 10
def province
  municipality_after_merge.province
end