Module: Dozer::Mapperable::ClassMethods
- Defined in:
- lib/dozer/mapperable.rb
Instance Method Summary collapse
Instance Method Details
#mapping(options) ⇒ Object
6 7 8 9 10 11 12 13 |
# File 'lib/dozer/mapperable.rb', line 6 def mapping() = .with_indifferent_access raise ArgumentError, 'from is missing' if [:from].nil? raise ArgumentError, 'to is missing' if [:to].nil? dozer_forward_mapper[[:from]] = [:to].to_sym dozer_backward_mapper[[:to]] = [:from].to_sym end |
#transform(hash, options = {}) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/dozer/mapperable.rb', line 23 def transform(hash, ={}) result = {}.with_indifferent_access = .with_indifferent_access mapper = if [:reverse] == true dozer_backward_mapper else dozer_forward_mapper end hash.each do |k, v| new_key = mapper[k] result[new_key] = v if new_key end result end |