Class: DataAnon::Strategy::Field::RandomFullName

Inherits:
Object
  • Object
show all
Defined in:
lib/strategy/field/name/random_full_name.rb

Overview

Generates full name using the RandomFirstName and RandomLastName strategies.

anonymize('FullName').using FieldStrategy::RandomFullName.new

!!!ruby
anonymize('FullName').using FieldStrategy::RandomLastName.new('my_first_names.txt', 'my_last_names.txt')

Instance Method Summary collapse

Constructor Details

#initialize(first_names = nil, last_names = nil) ⇒ RandomFullName

Returns a new instance of RandomFullName.


15
16
17
18
# File 'lib/strategy/field/name/random_full_name.rb', line 15

def initialize first_names = nil, last_names = nil
  @first_name_anonymizer = DataAnon::Strategy::Field::RandomFirstName.new(first_names)
  @last_name_anonymizer = DataAnon::Strategy::Field::RandomLastName.new(last_names)
end

Instance Method Details

#anonymize(field) ⇒ Object


20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/strategy/field/name/random_full_name.rb', line 20

def anonymize field

  name_words = field.value.split(' ')

  anonymized_first_name = @first_name_anonymizer.anonymize(field)
  anonymized_last_name = ""
  for counter in (1..name_words.size-1)
    anonymized_last_name = anonymized_last_name + " " + @last_name_anonymizer.anonymize(field)
  end

  return anonymized_first_name + anonymized_last_name

end