Class: Rehash::Mapper
- Inherits:
-
Object
- Object
- Rehash::Mapper
- Defined in:
- lib/rehash/mapper.rb
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
- #[](path) ⇒ Object
- #[]=(path, value) ⇒ Object
- #call(mapping, &block) ⇒ Object
-
#initialize(source, opts = Rehash.default_options) ⇒ Mapper
constructor
A new instance of Mapper.
- #map_array(mapping) ⇒ Object
- #map_hash(mapping) ⇒ Object
Constructor Details
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
3 4 5 |
# File 'lib/rehash/mapper.rb', line 3 def result @result end |
Instance Method Details
#[](path) ⇒ Object
25 26 27 |
# File 'lib/rehash/mapper.rb', line 25 def [](path) get_value(path) end |
#[]=(path, value) ⇒ Object
29 30 31 |
# File 'lib/rehash/mapper.rb', line 29 def []=(path, value) put_value(path, value) end |
#call(mapping, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/rehash/mapper.rb', line 12 def call(mapping, &block) default = mapping.delete(:default) if mapping.key?(:default) mapping.each do |from, to| value = get_value(from) value = default if value.nil? && !default.nil? value = yield value if block_given? put_value(to, value) end result end |