Class: DataCleaner::Format

Inherits:
Object
  • Object
show all
Defined in:
lib/data_cleaner/format.rb

Overview

DataCleaner::Format can be used to describe the format of an object’s attributes.

Example:

f = DataCleaner::Format.new("Person")
f.name [:first_name, " ", :last_name]

You most likely do not want to use this class directly, but instead through DataCleaner::Formats.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Format

:call-seq: Format.new(klass) -> format



17
18
19
20
# File 'lib/data_cleaner/format.rb', line 17

def initialize(klass)
  @klass = klass
  @attributes = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missingObject

:call-seq: format.attribute(:attr [, args…]) {|obj| block } -> format



29
30
31
32
33
# File 'lib/data_cleaner/format.rb', line 29

def attribute(name, *args, &block)
  args.push(block) if block
  attributes.push([name, args])
  self
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



13
14
15
# File 'lib/data_cleaner/format.rb', line 13

def attributes
  @attributes
end

#klassObject

Returns the value of attribute klass.



13
14
15
# File 'lib/data_cleaner/format.rb', line 13

def klass
  @klass
end

Instance Method Details

#attribute(name, *args, &block) ⇒ Object Also known as: method_missing

:call-seq: format.attribute(:attr [, args…]) {|obj| block } -> format



24
25
26
27
28
# File 'lib/data_cleaner/format.rb', line 24

def attribute(name, *args, &block)
  args.push(block) if block
  attributes.push([name, args])
  self
end