class Zizia::InputRecord

@example Building an importer with the factory

record = InputRecord.from({some: :metadata}, mapper: MyMapper.new)
record.some # => :metadata

Attributes

mapper[RW]

@!attribute [rw] mapper

@return [#map_fields]

Public Class Methods

from(metadata:, mapper: Zizia.config.metadata_mapper_class.new) click to toggle source

@param metadata [Object] @param mapper [#map_fields]

@return [InputRecord] an input record mapping metadata with the given

mapper
# File lib/zizia/input_record.rb, line 28
def from(metadata:, mapper: Zizia.config.metadata_mapper_class.new)
  mapper.metadata = metadata
  new(mapper: mapper)
end
new(mapper: Zizia.config.metadata_mapper_class.new) click to toggle source

@param mapper [#map_fields]

# File lib/zizia/input_record.rb, line 17
def initialize(mapper: Zizia.config.metadata_mapper_class.new)
  self.mapper = mapper
end

Public Instance Methods

attributes() click to toggle source

@return [Hash<Symbol, Object>]

# 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
method_missing(method_name, *args, &block) click to toggle source

Respond to methods matching mapper fields

Calls superclass method
# 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
representative_file() click to toggle source

@return [String, nil] an identifier for the representative file; nil if

none is given.
# 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) click to toggle source

@see method_missing

Calls superclass method
# File lib/zizia/input_record.rb, line 61
def respond_to_missing?(method_name, include_private = false)
  mapper.field?(method_name) || super
end