Class: Zizia::HashMapper

Inherits:
MetadataMapper show all
Defined in:
lib/zizia/hash_mapper.rb

Overview

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.

Examples:

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

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

Direct Known Subclasses

HyraxBasicMetadataMapper

Instance Attribute Summary

Attributes inherited from MetadataMapper

#metadata

Instance Method Summary collapse

Methods inherited from MetadataMapper

#field?, #method_missing, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Zizia::MetadataMapper

Instance Method Details

#fieldsEnumerable<Symbol>

Returns The fields the mapper can process.

Returns:

  • (Enumerable<Symbol>)

    The fields the mapper can process



33
34
35
36
# File 'lib/zizia/hash_mapper.rb', line 33

def fields
  return [] if .nil?
  .keys.map(&:to_sym)
end

#map_field(name) ⇒ Object

See Also:

  • MetadataMapper#map_field


40
41
42
# File 'lib/zizia/hash_mapper.rb', line 40

def map_field(name)
  Array([name.to_s])
end

#metadata=(meta) ⇒ Hash<String, String>

Parameters:

  • meta (#to_h)

Returns:

  • (Hash<String, String>)


27
28
29
# File 'lib/zizia/hash_mapper.rb', line 27

def metadata=(meta)
  @metadata = meta.to_h
end