Class: DataAnon::Strategy::Field::DateTimeDelta

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

Overview

Shifts data randomly within given range. Default shifts date within 10 days + or - and shifts time within 30 minutes.

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

!!!ruby
# shifts date within 20 days and time within 50 minutes
anonymize('DateOfBirth').using FieldStrategy::DateTimeDelta.new(20, 50)

Direct Known Subclasses

TimeDelta

Constant Summary collapse

DEFAULT_DAY_DELTA =
10
DEFAULT_MINUTE_DELTA =
30

Instance Method Summary collapse

Constructor Details

#initialize(day_delta = DEFAULT_DAY_DELTA, minute_delta = DEFAULT_MINUTE_DELTA) ⇒ DateTimeDelta

Returns a new instance of DateTimeDelta.


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

def initialize day_delta = DEFAULT_DAY_DELTA, minute_delta = DEFAULT_MINUTE_DELTA
  @day_delta = day_delta
  @minute_delta =  minute_delta
end

Instance Method Details

#anonymize(field) ⇒ Object


24
25
26
27
28
# File 'lib/strategy/field/datetime/date_time_delta.rb', line 24

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