Class: DataAnon::Strategy::Field::DefaultAnon

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

Constant Summary collapse

DEFAULT_STRATEGIES =
{:string => FieldStrategy::RandomString.new,
                      :fixnum => FieldStrategy::RandomIntegerDelta.new(5),
                      :bignum => FieldStrategy::RandomIntegerDelta.new(5000),
                      :float => FieldStrategy::RandomFloatDelta.new(5.0),
                      :bigdecimal => FieldStrategy::RandomBigDecimalDelta.new(500.0),
                      :datetime => FieldStrategy::DateTimeDelta.new,
                      :time => FieldStrategy::TimeDelta.new,
                      :date => FieldStrategy::DateDelta.new,
                      :array => FieldStrategy::AnonymizeArray.new(nil),
                      :trueclass => FieldStrategy::RandomBoolean.new,
                      :"bson::objectid" => FieldStrategy::Whitelist.new,
                      :falseclass => FieldStrategy::RandomBoolean.new
}

Instance Method Summary collapse

Constructor Details

#initialize(user_defaults = {}) ⇒ DefaultAnon

Returns a new instance of DefaultAnon.


21
22
23
24
# File 'lib/strategy/field/default_anon.rb', line 21

def initialize user_defaults = {}
  @user_defaults = DEFAULT_STRATEGIES.merge user_defaults
  FieldStrategy::AnonymizeArray.user_defaults @user_defaults
end

Instance Method Details

#anonymize(field) ⇒ Object


26
27
28
29
30
# File 'lib/strategy/field/default_anon.rb', line 26

def anonymize field
  strategy = @user_defaults[field.value.class.to_s.downcase.to_sym]
  raise "No strategy defined for datatype #{field.value.class}. Use 'default_field_strategies' option in your script. Refer to  http://sunitparekh.github.com/data-anonymization/#default-field-strategies for more details. #{field.inspect}" unless strategy
  strategy.anonymize field
end