class Zizia::HashMapper

A generic metadata mapper for input records

Maps from hash accessor syntax (`['title']`) to method call dot syntax (`.title`)

The fields provided by this mapper are dynamically determined by the fields available in the provided metadata hash.

All field values are given as multi-valued arrays.

@example

mapper = HashMapper.new
mapper.fields # => []

mapper.metadata = { title: 'Comet in Moominland', author: 'Tove Jansson' }
mapper.fields # => [:title, :author]
mapper.title  # => ['Comet in Moominland']
mapper.author # => ['Tove Jansson']

Public Instance Methods

fields() click to toggle source

@return [Enumerable<Symbol>] The fields the mapper can process

# File lib/zizia/hash_mapper.rb, line 33
def fields
  return [] if metadata.nil?
  metadata.keys.map(&:to_sym)
end
map_field(name) click to toggle source

@see MetadataMapper#map_field

# File lib/zizia/hash_mapper.rb, line 40
def map_field(name)
  Array(metadata[name.to_s])
end
metadata=(meta) click to toggle source

@param meta [#to_h] @return [Hash<String, String>]

# File lib/zizia/hash_mapper.rb, line 27
def metadata=(meta)
  @metadata = meta.to_h
end