Class: DataAnon::Strategy::Field::StringTemplate

Inherits:
Object
  • Object
show all
Defined in:
lib/strategy/field/string/string_template.rb

Overview

Simple string evaluation within [DataAnon::Core::Field](#dataanon-core-field) context. Can be used for email, username anonymization. Make sure to put the string in 'single quote' else it will get evaluated inline.

anonymize('UserName').using FieldStrategy::StringTemplate.new('user#{row_number}')

!!!ruby
anonymize('Email').using FieldStrategy::StringTemplate.new('valid.address+#{row_number}@gmail.com')

!!!ruby
anonymize('Email').using FieldStrategy::StringTemplate.new('useremail#{row_number}@mailinator.com')

Instance Method Summary collapse

Constructor Details

#initialize(template) ⇒ StringTemplate

Returns a new instance of StringTemplate.


19
20
21
# File 'lib/strategy/field/string/string_template.rb', line 19

def initialize template
  @template = template
end

Instance Method Details

#anonymize(field) ⇒ Object


23
24
25
26
# File 'lib/strategy/field/string/string_template.rb', line 23

def anonymize field
  context = field.instance_eval { binding }
  eval ('"' + @template + '"'), context
end