Module: DataCleaner::Cleaner

Extended by:
Cleaner
Included in:
Cleaner
Defined in:
lib/data_cleaner/cleaner.rb

Overview

DataCleaner::Cleaner is a module which can either be mixed-in, or used standalone to anonymise the data held within objects.

DataCleaner::Cleaner relies on the object formats specified with DataCleaner::Formats.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.clean_value(attribute, klass = self, object = nil) ⇒ Object

:call-seq: Cleaner.clean_value(attr, klass, instance=nil) -> clean_value

Returns a clean value accoring to the format for the attribute and class specified. Be aware that if the format definition includes a block you many need to supply an instance of the class or you may get errors.



16
17
18
19
# File 'lib/data_cleaner/cleaner.rb', line 16

def self.clean_value(attribute, klass=self, object=nil)
  arguments = DataCleaner::Formats.attribute_format(klass, attribute)
  __replacement__(arguments, object)
end

Instance Method Details

#__clean__(object = self) ⇒ Object Also known as: clean

:call-seq: Cleaner.clean(obj) -> new_obj obj.clean -> new_obj

Returns an anonymised copy of obj.

Relies on obj.dup.



30
31
32
# File 'lib/data_cleaner/cleaner.rb', line 30

def __clean__(object=self)
  __clean__!(object.dup)
end

#__clean__!(object = self) ⇒ Object Also known as: clean!

:call-seq: Cleaner.clean!(obj) -> obj obj.clean! -> obj

Anonymises obj.



42
43
44
45
46
47
48
49
# File 'lib/data_cleaner/cleaner.rb', line 42

def __clean__!(object=self)
  format = DataCleaner::Formats.formats[object.class.name]
  
  format.attributes.each do |attribute, arguments|
    object.send(:"#{attribute}=", __replacement__(arguments, object))
  end
  object
end