class HashMath::Mapper::Mapping

Represents one complete configuration for mapping one key-value pair to one lookup.

Example:


mapping = Mapper.make(

lookup: { name: :patient_statuses, by: :name },
value: :status,
set: :patient_status_id,
with: :id

).add(id: 1, name: 'active').add(id: 2, name: 'inactive')

patient = { id: 1, code: 'active' } mapped_patient = mapping.map!(patient)


mapped_patient now equals: { id: 1, code: 'active', patient_status_id: 1 }

Attributes

lookup[R]
set[R]
value[R]
with[R]

Public Class Methods

new(lookup:, value:, set:, with:) click to toggle source

lookup: can either be a Mapper#Lookup instance or a hash with the attributes to initialize for a Mapper#Lookup instance. value: the key to use to get the 'value' from the object to lookup. set: the key to set once the lookup record is identified. with: the key use, on the lookup, to get the new value.

# File lib/hash_math/mapper/mapping.rb, line 43
def initialize(lookup:, value:, set:, with:)
  @lookup = Lookup.make(lookup)
  @value  = value
  @set    = set
  @with   = with

  freeze
end

Private Instance Methods

proc_or_brackets(object, thing) click to toggle source
# File lib/hash_math/mapper/mapping.rb, line 70
def proc_or_brackets(object, thing)
  return nil unless object

  thing.is_a?(Proc) ? thing.call(object) : object[thing]
end