Class: DataAnon::Strategy::Field::RandomIntegerDelta

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

Overview

Shifts the current value randomly within given delta + and -. Default is 10

anonymize('Age').using FieldStrategy::RandomIntegerDelta.new(2)

Instance Method Summary collapse

Constructor Details

#initialize(delta = 10) ⇒ RandomIntegerDelta

Returns a new instance of RandomIntegerDelta.


12
13
14
# File 'lib/strategy/field/number/random_integer_delta.rb', line 12

def initialize delta = 10
  @delta = delta
end

Instance Method Details

#anonymize(field) ⇒ Object


16
17
18
19
# File 'lib/strategy/field/number/random_integer_delta.rb', line 16

def anonymize field
  adjustment = DataAnon::Utils::RandomInt.generate(-@delta,@delta)
  return field.value + adjustment
end