Class: HashMapper::Map

Inherits:
Object
  • Object
show all
Defined in:
lib/hash_mapper.rb

Overview

Contains PathMaps Makes them interact

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path_from, path_to, options = {}) ⇒ Map

Returns a new instance of Map.



119
120
121
122
123
124
# File 'lib/hash_mapper.rb', line 119

def initialize(path_from, path_to, options = {})
  @path_from = path_from
  @path_to = path_to
  @delegated_mapper = options.fetch(:using, nil)
  @default_value = options.fetch(:default, :hash_mapper_no_default)
end

Instance Attribute Details

#default_valueObject (readonly)

Returns the value of attribute default_value.



117
118
119
# File 'lib/hash_mapper.rb', line 117

def default_value
  @default_value
end

#delegated_mapperObject (readonly)

Returns the value of attribute delegated_mapper.



117
118
119
# File 'lib/hash_mapper.rb', line 117

def delegated_mapper
  @delegated_mapper
end

#path_fromObject (readonly)

Returns the value of attribute path_from.



117
118
119
# File 'lib/hash_mapper.rb', line 117

def path_from
  @path_from
end

#path_toObject (readonly)

Returns the value of attribute path_to.



117
118
119
# File 'lib/hash_mapper.rb', line 117

def path_to
  @path_to
end

Instance Method Details

#process_into(output, input, meth = :normalize) ⇒ Object



126
127
128
129
130
# File 'lib/hash_mapper.rb', line 126

def process_into(output, input, meth = :normalize)
  path_1, path_2 = (meth == :normalize ? [path_from, path_to] : [path_to, path_from])
  value = get_value_from_input(output, input, path_1, meth)
  set_value_in_output(output, path_2, value)
end