Module: INE::Places
- Defined in:
- lib/ine.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('../ine/places/', __FILE__)
- Version =
"0.6.1"
Class Method Summary
collapse
Class Method Details
.hydratate(klass, data_path, options) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
# File 'lib/ine.rb', line 37
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
|