Class: Municipitaly2::Data

Inherits:
Object
  • Object
show all
Defined in:
lib/municipitaly2/data.rb

Overview

Define collection

Constant Summary collapse

@@zones =
[]
@@regions =
[]
@@provinces =
[]
@@municipalities =
[]

Instance Method Summary collapse

Instance Method Details

#find_csv(file) ⇒ Object



54
55
56
57
# File 'lib/municipitaly2/data.rb', line 54

def find_csv(file)
  File.expand_path(File.join(File.dirname(__FILE__),
                             "../../vendor/data/#{file}"))
end

#municipalities ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/municipitaly2/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], name_alt: row[2], partial_istat: row[3],
                         cadastrial_code: row[4], postal_codes: row[5],
                         population: row[6], area: row[7],
                         latitude: row[8], longitude: row[9])
    end
  end
  @@municipalities
end

#provinces ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/municipitaly2/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 ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/municipitaly2/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 ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/municipitaly2/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