class Municipitaly::Data

Define collection

Public Instance Methods

find_csv(file) click to toggle source
# File lib/municipitaly/data.rb, line 53
def find_csv(file)
  File.expand_path(File.join(File.dirname(__FILE__),
                             "../../vendor/data/#{file}"))
end
municipalities() click to toggle source
# File lib/municipitaly/data.rb, line 40
def municipalities
  if @@municipalities.empty?
    CSV.foreach(find_csv('municipalities.csv'), headers: true) do |row|
      @@municipalities <<
        Municipality.new(province_istat: row[0],
                         name: row[1], partial_istat: row[2],
                         cadastrial_code: row[3], postal_codes: row[4],
                         population: row[5])
    end
  end
  @@municipalities
end
provinces() click to toggle source
# File lib/municipitaly/data.rb, line 30
def provinces
  if @@provinces.empty?
    CSV.foreach(find_csv('provinces.csv'), headers: true) do |row|
      @@provinces << Province.new(region_istat: row[0], name: row[1],
                                  istat: row[2], acronym: row[3])
    end
  end
  @@provinces
end
regions() click to toggle source
# File lib/municipitaly/data.rb, line 20
def regions
  if @@regions.empty?
    CSV.foreach(find_csv('regions.csv'), headers: true) do |row|
      @@regions << Region.new(zone_code: row[0], name: row[1],
                              istat: row[2], partial_iso3166: row[3])
    end
  end
  @@regions
end
zones() click to toggle source
# File lib/municipitaly/data.rb, line 11
def zones
  if @@zones.empty?
    CSV.foreach(find_csv('zones.csv'), headers: true) do |row|
      @@zones << Zone.new(name: row[0], code: row[1])
    end
  end
  @@zones
end