Class: Caster::Add

Inherits:
Object
  • Object
show all
Defined in:
lib/caster/transform/add.rb

Instance Method Summary collapse

Constructor Details

#initialize(field, value) ⇒ Add

Returns a new instance of Add.



7
8
9
10
11
# File 'lib/caster/transform/add.rb', line 7

def initialize field, value
  @field = field
  @value = value
  @accessor = Accessor.new
end

Instance Method Details

#evaluate(obj, target_doc) ⇒ Object



18
19
20
# File 'lib/caster/transform/add.rb', line 18

def evaluate obj, target_doc
  (obj.is_a? Reference)? obj.evaluate(target_doc) : obj
end

#execute(doc) ⇒ Object



13
14
15
16
# File 'lib/caster/transform/add.rb', line 13

def execute doc
  @accessor.set doc, @field, evaluate(@value, doc)
  doc
end