Class: DataAnon::Strategy::Field::DateDelta

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

Overview

Shifts date randomly within given delta range. Default shits date within 10 days + or -

anonymize('DateOfBirth').using FieldStrategy::AnonymizeDate.new

!!!ruby
# shifts date within 25 days
anonymize('DateOfBirth').using FieldStrategy::DateDelta.new(25)

Constant Summary collapse

DEFAULT_DAY_DELTA =
10

Instance Method Summary collapse

Constructor Details

#initialize(day_delta = DEFAULT_DAY_DELTA) ⇒ DateDelta

Returns a new instance of DateDelta.


19
20
21
# File 'lib/strategy/field/datetime/date_delta.rb', line 19

def initialize day_delta = DEFAULT_DAY_DELTA
  @day_delta = day_delta
end

Instance Method Details

#anonymize(field) ⇒ Object


23
24
25
26
# File 'lib/strategy/field/datetime/date_delta.rb', line 23

def anonymize field
  day_adjustment = DataAnon::Utils::RandomInt.generate(-@day_delta,@day_delta)
  return field.value + day_adjustment.days
end