Class: OvertureMaps::Import::RecordMapper
- Inherits:
-
Object
- Object
- OvertureMaps::Import::RecordMapper
- Defined in:
- lib/overture_maps/import/record_mapper.rb
Overview
Maps raw Overture records (nested structs from parquet) onto flat model attributes. Every record gets the same key set — heterogeneous keys make ActiveRecord's insert_all/upsert_all reject the whole batch.
Instance Attribute Summary collapse
-
#model_class ⇒ Object
readonly
Returns the value of attribute model_class.
-
#release ⇒ Object
readonly
Returns the value of attribute release.
-
#theme ⇒ Object
readonly
Returns the value of attribute theme.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#call(record) ⇒ Object
Returns attributes with a stable key set, or nil if the record can't be mapped (caller records the error).
-
#initialize(theme:, model_class:, type: nil, release: nil) ⇒ RecordMapper
constructor
A new instance of RecordMapper.
-
#key_set ⇒ Object
The attribute keys every mapped record will contain.
Constructor Details
#initialize(theme:, model_class:, type: nil, release: nil) ⇒ RecordMapper
Returns a new instance of RecordMapper.
15 16 17 18 19 20 21 |
# File 'lib/overture_maps/import/record_mapper.rb', line 15 def initialize(theme:, model_class:, type: nil, release: nil) @theme = theme @type = type @model_class = model_class @release = release @columns = model_class.column_names end |
Instance Attribute Details
#model_class ⇒ Object (readonly)
Returns the value of attribute model_class.
13 14 15 |
# File 'lib/overture_maps/import/record_mapper.rb', line 13 def model_class @model_class end |
#release ⇒ Object (readonly)
Returns the value of attribute release.
13 14 15 |
# File 'lib/overture_maps/import/record_mapper.rb', line 13 def release @release end |
#theme ⇒ Object (readonly)
Returns the value of attribute theme.
13 14 15 |
# File 'lib/overture_maps/import/record_mapper.rb', line 13 def theme @theme end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
13 14 15 |
# File 'lib/overture_maps/import/record_mapper.rb', line 13 def type @type end |
Class Method Details
.for(theme:, model_class:, type: nil, release: nil) ⇒ Object
9 10 11 |
# File 'lib/overture_maps/import/record_mapper.rb', line 9 def self.for(theme:, model_class:, type: nil, release: nil) new(theme: theme, model_class: model_class, type: type, release: release) end |
Instance Method Details
#call(record) ⇒ Object
Returns attributes with a stable key set, or nil if the record can't be mapped (caller records the error).
25 26 27 28 29 |
# File 'lib/overture_maps/import/record_mapper.rb', line 25 def call(record) attrs = base_attributes(record) attrs.merge!(theme_attributes(record)) normalize(attrs) end |
#key_set ⇒ Object
The attribute keys every mapped record will contain.
32 33 34 35 36 37 38 |
# File 'lib/overture_maps/import/record_mapper.rb', line 32 def key_set @key_set ||= begin sample = base_attributes({}).merge(theme_attributes({})) keys = sample.keys.select { |k| @columns.include?(k.to_s) } keys | %i[id geometry] end end |