Class: HashMapper::Map
- Inherits:
-
Object
- Object
- HashMapper::Map
- Defined in:
- lib/hash_mapper.rb
Overview
Contains PathMaps Makes them interact
Instance Attribute Summary collapse
-
#default_value ⇒ Object
readonly
Returns the value of attribute default_value.
-
#delegated_mapper ⇒ Object
readonly
Returns the value of attribute delegated_mapper.
-
#path_from ⇒ Object
readonly
Returns the value of attribute path_from.
-
#path_to ⇒ Object
readonly
Returns the value of attribute path_to.
Instance Method Summary collapse
-
#initialize(path_from, path_to, options = {}) ⇒ Map
constructor
A new instance of Map.
- #process_into(output, input, method_name: :normalize, context: nil) ⇒ Object
Constructor Details
#initialize(path_from, path_to, options = {}) ⇒ Map
Returns a new instance of Map.
133 134 135 136 137 138 |
# File 'lib/hash_mapper.rb', line 133 def initialize(path_from, path_to, = {}) @path_from = path_from @path_to = path_to @delegated_mapper = .fetch(:using, nil) @default_value = .fetch(:default, NO_DEFAULT) end |
Instance Attribute Details
#default_value ⇒ Object (readonly)
Returns the value of attribute default_value.
131 132 133 |
# File 'lib/hash_mapper.rb', line 131 def default_value @default_value end |
#delegated_mapper ⇒ Object (readonly)
Returns the value of attribute delegated_mapper.
131 132 133 |
# File 'lib/hash_mapper.rb', line 131 def delegated_mapper @delegated_mapper end |
#path_from ⇒ Object (readonly)
Returns the value of attribute path_from.
131 132 133 |
# File 'lib/hash_mapper.rb', line 131 def path_from @path_from end |
#path_to ⇒ Object (readonly)
Returns the value of attribute path_to.
131 132 133 |
# File 'lib/hash_mapper.rb', line 131 def path_to @path_to end |
Instance Method Details
#process_into(output, input, method_name: :normalize, context: nil) ⇒ Object
140 141 142 143 144 |
# File 'lib/hash_mapper.rb', line 140 def process_into(output, input, method_name: :normalize, context: nil) path_1, path_2 = (method_name == :normalize ? [path_from, path_to] : [path_to, path_from]) value = get_value_from_input(output, input, path_1, method_name: method_name, context: context) set_value_in_output(output, path_2, value, context: context) end |