Class: Zizia::InputRecord
- Inherits:
-
Object
- Object
- Zizia::InputRecord
- Defined in:
- lib/zizia/input_record.rb
Overview
Instance Attribute Summary collapse
Class Method Summary collapse
-
.from(metadata:, mapper: Zizia.config.metadata_mapper_class.new) ⇒ InputRecord
An input record mapping metadata with the given mapper.
Instance Method Summary collapse
- #attributes ⇒ Hash<Symbol, Object>
-
#initialize(mapper: Zizia.config.metadata_mapper_class.new) ⇒ InputRecord
constructor
A new instance of InputRecord.
-
#method_missing(method_name, *args, &block) ⇒ Object
Respond to methods matching mapper fields.
-
#representative_file ⇒ String?
An identifier for the representative file; nil if none is given.
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(mapper: Zizia.config.metadata_mapper_class.new) ⇒ InputRecord
Returns a new instance of InputRecord.
17 18 19 |
# File 'lib/zizia/input_record.rb', line 17 def initialize(mapper: Zizia.config..new) self.mapper = mapper end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
Respond to methods matching mapper fields
54 55 56 57 |
# File 'lib/zizia/input_record.rb', line 54 def method_missing(method_name, *args, &block) return super unless mapper.field?(method_name) mapper.public_send(method_name) end |
Instance Attribute Details
#mapper ⇒ #map_fields
13 14 15 |
# File 'lib/zizia/input_record.rb', line 13 def mapper @mapper end |
Class Method Details
.from(metadata:, mapper: Zizia.config.metadata_mapper_class.new) ⇒ InputRecord
Returns an input record mapping metadata with the given mapper.
28 29 30 31 |
# File 'lib/zizia/input_record.rb', line 28 def from(metadata:, mapper: Zizia.config..new) mapper. = new(mapper: mapper) end |
Instance Method Details
#attributes ⇒ Hash<Symbol, Object>
36 37 38 39 40 |
# File 'lib/zizia/input_record.rb', line 36 def attributes mapper.fields.each_with_object({}) do |field, attrs| attrs[field] = public_send(field) end end |
#representative_file ⇒ String?
Returns an identifier for the representative file; nil if none is given.
45 46 47 48 49 50 |
# File 'lib/zizia/input_record.rb', line 45 def representative_file return mapper.representative_file if mapper.respond_to?(:representative_file) nil end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
61 62 63 |
# File 'lib/zizia/input_record.rb', line 61 def respond_to_missing?(method_name, include_private = false) mapper.field?(method_name) || super end |