class NlApi::Municipality
Attributes
filename[W]
provinces[W]
code[R]
name[R]
province_code[R]
province_name[R]
Public Class Methods
all()
click to toggle source
# File lib/nl_api/municipality.rb, line 49 def all @all ||= read_csv end
each(&block)
click to toggle source
# File lib/nl_api/municipality.rb, line 53 def each(&block) all.each(&block) self end
filename()
click to toggle source
# File lib/nl_api/municipality.rb, line 26 def filename @filename ||= '../../data/gemeentenalfabetisch2016.csv' end
find_all_by(where)
click to toggle source
# File lib/nl_api/municipality.rb, line 65 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/municipality.rb, line 58 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/municipality.rb, line 4 def initialize(attributes) @code = attributes[:code] @name = attributes[:name] @province_name = attributes[:province_name] @province_code = attributes[:province_code] end
path()
click to toggle source
# File lib/nl_api/municipality.rb, line 30 def path File.join(File.dirname(File.expand_path(__FILE__)), filename) end
provinces()
click to toggle source
# File lib/nl_api/municipality.rb, line 45 def provinces @provinces ||= {} end
read_csv()
click to toggle source
# File lib/nl_api/municipality.rb, line 34 def read_csv @store ||= CSV.read(path, headers: true, col_sep: ';').map do |line| NlApi::Municipality.new( code: line[0].to_i, name: line[1], province_name: line[2], province_code: line[3].to_i ) end end
Public Instance Methods
merged_municipalities()
click to toggle source
# File lib/nl_api/municipality.rb, line 15 def merged_municipalities NlApi::HistoricMunicipality.find_all_by(code_after_merge: code) end
province()
click to toggle source
# File lib/nl_api/municipality.rb, line 11 def province self.class.provinces[province_code] ||= NlApi::Province.new(province_code, province_name) end