Module: INE::Places

Defined in:
lib/ine/places.rb,
lib/ine/places/version.rb

Defined Under Namespace

Modules: CSVRecord Classes: AutonomousRegion, AutonomousRegionsCollection, Place, PlacesCollection, Province, ProvincesCollection

Constant Summary collapse

ROOT =
File.expand_path('../places/', __FILE__)
VERSION =
"0.3.0"

Class Method Summary collapse

Class Method Details

.hydratate(klass, data_path, options) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ine/places.rb', line 28

def self.hydratate(klass, data_path, options)
  data = CSV.read(open(data_path), headers: true)

  data.each do |row|
    if obj = klass.find(row[options[:id_column]])
      value = row[options[:value_column]]
      case options[:convert_to]
      when :float
        value = value.to_f
      when :integer, :int
        value = value.to_i
      end

      obj.data.send((options[:as].to_s + '=').to_sym, value)
    end
  end

  nil
end

.preloadObject



20
21
22
23
24
25
26
# File 'lib/ine/places.rb', line 20

def self.preload
  AutonomousRegionsCollection.records
  ProvincesCollection.records
  PlacesCollection.records

  nil
end