Class: Dozer::Rule

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Rule

Returns a new instance of Rule.



5
6
7
8
9
10
11
12
13
# File 'lib/dozer/rule.rb', line 5

def initialize(options)
  options = options.with_indifferent_access
  validate!(options)

  @base_klass = options[:base_klass]
  @from = options[:from].to_sym
  @to   = options[:to].to_sym
  @func = options[:func]
end

Instance Attribute Details

#base_klassObject

Returns the value of attribute base_klass.



3
4
5
# File 'lib/dozer/rule.rb', line 3

def base_klass
  @base_klass
end

#fromObject

Returns the value of attribute from.



3
4
5
# File 'lib/dozer/rule.rb', line 3

def from
  @from
end

#funcObject

Returns the value of attribute func.



3
4
5
# File 'lib/dozer/rule.rb', line 3

def func
  @func
end

#toObject

Returns the value of attribute to.



3
4
5
# File 'lib/dozer/rule.rb', line 3

def to
  @to
end

Instance Method Details

#apply(input) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/dozer/rule.rb', line 15

def apply(input)
  if applicable?(input)
    [to, evaluate(input[from])]
  else
    nil
  end
end