class DataAnon::Strategy::Field::SelectFromFile

Similar to SelectFromList only difference is the list of values are picked up from file. Classical usage is like states field anonymization.

!!!ruby
anonymize('State').using FieldStrategy::SelectFromFile.new('states.txt')

Public Class Methods

new(file_path) click to toggle source
# File lib/strategy/field/string/select_from_file.rb, line 13
def initialize file_path
  @values = File.read(file_path).split
end

Public Instance Methods

anonymize(field) click to toggle source
# File lib/strategy/field/string/select_from_file.rb, line 17
def anonymize field
  return @values.sample(field.value.length) if field.value.kind_of? Array
  @values.sample
end