Module: Dozer::Mapperable::ClassMethods

Defined in:
lib/dozer/mapperable.rb

Instance Method Summary collapse

Instance Method Details

#mapping(options) ⇒ Object



6
7
8
9
# File 'lib/dozer/mapperable.rb', line 6

def mapping(options)
  rule = Dozer::Rule.new(options.merge(base_klass: self))
  append_rule(rule)
end

#transform(input, options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/dozer/mapperable.rb', line 11

def transform(input, options={})
  input, output = input.with_indifferent_access, ActiveSupport::HashWithIndifferentAccess.new
  kvs = all_rules.map { |rule| rule.apply(input) }.compact!
  kvs.each do |kv|
    key, value = kv.first, kv.last
    output[key] = value
  end

  output
end