Class: Krikri::Mapping
- Inherits:
-
Object
- Object
- Krikri::Mapping
- Includes:
- MappingDSL
- Defined in:
- lib/krikri/mapping.rb
Overview
Handles transformation of OriginalRecords into a target class.
map = Mapping.new(MyModelClass)
map.dsl_method args
map.process_record(my_original_record)
# => #<MyModelClass:0x3ff8b7459210()>
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
Instance Method Summary collapse
-
#initialize(klass = DPLA::MAP::Aggregation, parser = Krikri::XmlParser) ⇒ Mapping
constructor
A new instance of Mapping.
-
#process_record(record) ⇒ Object
A model object of type @klass, processed through the mapping DSL.
Methods included from MappingDSL
#method_missing, #properties, #respond_to_missing?
Methods included from Krikri::MappingDSL::RdfSubjects
Methods included from Krikri::MappingDSL::ParserMethods
#local_name, #record, #record_uri
Constructor Details
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Krikri::MappingDSL
Instance Attribute Details
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
13 14 15 |
# File 'lib/krikri/mapping.rb', line 13 def klass @klass end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
13 14 15 |
# File 'lib/krikri/mapping.rb', line 13 def parser @parser end |
Instance Method Details
#process_record(record) ⇒ Object
Returns A model object of type @klass, processed through the mapping DSL.
27 28 29 30 31 32 33 |
# File 'lib/krikri/mapping.rb', line 27 def process_record(record) mapped_record = klass.new properties.each do |prop| prop.to_proc.call(mapped_record, parser.parse(record)) end mapped_record end |