data_cleaner 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/data_cleaner/cleaner.rb +11 -0
- data/lib/data_cleaner/formats.rb +14 -1
- metadata +4 -4
data/lib/data_cleaner/cleaner.rb
CHANGED
@@ -58,6 +58,17 @@ module DataCleaner
|
|
58
58
|
:words => Faker::Lorem,
|
59
59
|
}
|
60
60
|
|
61
|
+
# :call-seq: Cleaner.clean_value(attr, klass, instance=nil) -> clean_value
|
62
|
+
#
|
63
|
+
# Returns a clean value accoring to the format for the attribute and class
|
64
|
+
# specified. Be aware that if the format definition includes a block you
|
65
|
+
# many need to supply an instance of the class or you may get errors.
|
66
|
+
#
|
67
|
+
def self.clean_value(attribute, klass=self, object=nil)
|
68
|
+
arguments = DataCleaner::Formats.attribute_format(klass, attribute)
|
69
|
+
__replacement__(arguments, object)
|
70
|
+
end
|
71
|
+
|
61
72
|
extend self
|
62
73
|
|
63
74
|
# :call-seq: Cleaner.clean(obj) -> new_obj
|
data/lib/data_cleaner/formats.rb
CHANGED
@@ -36,7 +36,7 @@ module DataCleaner
|
|
36
36
|
class << self; attr_accessor :formats end
|
37
37
|
self.formats = {}
|
38
38
|
|
39
|
-
# :call-seq: format(klass) {|format| block } -> format
|
39
|
+
# :call-seq: Formats.format(klass) {|format| block } -> format
|
40
40
|
#
|
41
41
|
# Yields a format object, which can be used to describe the format of klass.
|
42
42
|
#
|
@@ -46,5 +46,18 @@ module DataCleaner
|
|
46
46
|
formats[klass.to_s] = obj
|
47
47
|
end
|
48
48
|
|
49
|
+
# :call-seq: Formats.attribute_format(klass, attribute) -> attribute_format
|
50
|
+
#
|
51
|
+
# Returns the format for a particular attribute as described in a format
|
52
|
+
# block.
|
53
|
+
#
|
54
|
+
def self.attribute_format(klass, attribute)
|
55
|
+
format = formats[klass.to_s]
|
56
|
+
if format
|
57
|
+
attribute, attribute_format = format.attributes.assoc(attribute.to_sym)
|
58
|
+
attribute_format
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
49
62
|
end
|
50
63
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: data_cleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 3
|
10
|
+
version: 0.0.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Matthew Sadler
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-04 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|