Class: DataAnon::Strategy::Field::SelectFromFile
- Inherits:
-
Object
- Object
- DataAnon::Strategy::Field::SelectFromFile
- Defined in:
- lib/strategy/field/string/select_from_file.rb
Overview
Similar to SelectFromList only difference is the list of values are picked up from file. Classical usage is like states field anonymization.
anonymize('State').using FieldStrategy::SelectFromFile.new('states.txt')
Direct Known Subclasses
RandomFirstName, RandomLastName, SelectFromDatabase, SelectFromList
Instance Method Summary collapse
- #anonymize(field) ⇒ Object
-
#initialize(file_path) ⇒ SelectFromFile
constructor
A new instance of SelectFromFile.
Constructor Details
#initialize(file_path) ⇒ SelectFromFile
Returns a new instance of SelectFromFile.
13 14 15 |
# File 'lib/strategy/field/string/select_from_file.rb', line 13 def initialize file_path @values = File.read(file_path).split end |
Instance Method Details
#anonymize(field) ⇒ Object
17 18 19 20 |
# 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 |