Class: Scrubber::FieldTransform

Inherits:
Object
  • Object
show all
Defined in:
lib/scrubber/field_transform.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(field, options = {}) ⇒ FieldTransform

Returns a new instance of FieldTransform.



4
5
6
7
8
9
10
# File 'lib/scrubber/field_transform.rb', line 4

def initialize(field, options = {})
  @field = field.to_s
  unless options.has_key?(:set_to)
    raise "Please specify what you'd like to change the field #{field} to with a :set_to"
  end
  @set_to = options[:set_to]
end

Instance Attribute Details

#fieldObject (readonly)

Returns the value of attribute field.



3
4
5
# File 'lib/scrubber/field_transform.rb', line 3

def field
  @field
end

#set_toObject (readonly)

Returns the value of attribute set_to.



3
4
5
# File 'lib/scrubber/field_transform.rb', line 3

def set_to
  @set_to
end

Instance Method Details

#perform_on(record) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/scrubber/field_transform.rb', line 12

def perform_on(record)
  val = nil
  if @set_to.is_a?(String)
    val = interpolate_string_for(record)
  else
    val = @set_to
  end

  record.send("#{@field}=", val)
end