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.
Instance Attribute Summary collapse
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
-
#parser ⇒ Object
readonly
Returns the value of attribute parser.
-
#parser_args ⇒ Object
readonly
Returns the value of attribute parser_args.
Instance Method Summary collapse
-
#initialize(klass = DPLA::MAP::Aggregation, parser = Krikri::XmlParser, *parser_args) ⇒ 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
#header, #local_name, #record, #record_uri
Constructor Details
#initialize(klass = DPLA::MAP::Aggregation, parser = Krikri::XmlParser, *parser_args) ⇒ Mapping
Returns a new instance of Mapping.
21 22 23 24 25 26 27 |
# File 'lib/krikri/mapping.rb', line 21 def initialize(klass = DPLA::MAP::Aggregation, parser = Krikri::XmlParser, *parser_args) @klass = klass @parser = parser @parser_args = parser_args end |
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.
14 15 16 |
# File 'lib/krikri/mapping.rb', line 14 def klass @klass end |
#parser ⇒ Object (readonly)
Returns the value of attribute parser.
14 15 16 |
# File 'lib/krikri/mapping.rb', line 14 def parser @parser end |
#parser_args ⇒ Object (readonly)
Returns the value of attribute parser_args.
14 15 16 |
# File 'lib/krikri/mapping.rb', line 14 def parser_args @parser_args end |
Instance Method Details
#process_record(record) ⇒ Object
Returns A model object of type @klass, processed through the mapping DSL.
34 35 36 37 38 39 40 |
# File 'lib/krikri/mapping.rb', line 34 def process_record(record) mapped_record = klass.new properties.each do |prop| prop.to_proc.call(mapped_record, parser.parse(record, *@parser_args)) end mapped_record end |