has_normalized_attributes 0.0.6 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +1 -4
- data/lib/has_normalized_attributes.rb +8 -7
- data/lib/version.rb +1 -1
- data/spec/db/test.sqlite3 +0 -0
- data/spec/has_normalized_fields_spec.rb +5 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91dc221ce7007d6265c70324eb766a71b7d094a0
|
4
|
+
data.tar.gz: f3d16b28f11791f70d98356f950b2fe346c8db2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d1fe3bacd965a7ef3880ccb64d38081413c5ccba78d3448a8babffd0be09219992d58f8dc619ab11d0cef93df74e5af3e3fa42257bd38946465adac08c7dbfc3
|
7
|
+
data.tar.gz: 211acf70d9871c0d78bdaa4c053d347970370256580831a84a3df63a7588016788d016475774057855a8a3afb0d9b1b458e3a02fff198eb3c5e8f25964822b95
|
data/.travis.yml
CHANGED
@@ -10,9 +10,8 @@ module HasNormalizedAttributes
|
|
10
10
|
# E.g. `normalize_dollar` will first call the original `normalize_dollar` method (super)
|
11
11
|
# and then use the result from that to check for parentheses.
|
12
12
|
define_method "normalize_#{ arg }" do
|
13
|
-
super()
|
14
|
-
|
15
|
-
end
|
13
|
+
result = super()
|
14
|
+
result.is_a?(String) ? result.sub(/\A\((.*)\)\Z/, '-\1') : result
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
@@ -35,10 +34,10 @@ module HasNormalizedAttributes
|
|
35
34
|
args.each do |arg|
|
36
35
|
define_method "normalize_#{arg}" do
|
37
36
|
if arg == :strip
|
38
|
-
self ? self.strip
|
37
|
+
self ? self.strip : self
|
39
38
|
else
|
40
39
|
reg_exp = HasNormalizedAttributes.const_get(arg.upcase)
|
41
|
-
self && is_a?(String) && match(reg_exp) ? gsub
|
40
|
+
self && is_a?(String) && match(reg_exp) ? gsub(reg_exp,'') : self
|
42
41
|
end
|
43
42
|
end
|
44
43
|
end
|
@@ -58,9 +57,11 @@ module HasNormalizedAttributes
|
|
58
57
|
args.each do |field, normalization_type|
|
59
58
|
define_method "#{field.to_s}=" do |value|
|
60
59
|
if value.present?
|
61
|
-
value.send("normalize_#{normalization_type.downcase}".to_sym)
|
60
|
+
normalized_value = value.send("normalize_#{normalization_type.downcase}".to_sym)
|
61
|
+
else
|
62
|
+
normalized_value = value
|
62
63
|
end
|
63
|
-
super
|
64
|
+
super normalized_value
|
64
65
|
end
|
65
66
|
end
|
66
67
|
|
data/lib/version.rb
CHANGED
data/spec/db/test.sqlite3
CHANGED
Binary file
|
@@ -97,6 +97,7 @@ describe "HasNormalizedAttributes" do
|
|
97
97
|
it{@resource.dollar_attr = "(321.45)";@resource.dollar_attr.should == "-321.45"}
|
98
98
|
it{@resource.dollar_attr = "$(321.45)";@resource.dollar_attr.should == "-321.45"}
|
99
99
|
it{@resource.dollar_attr = "($321.45)";@resource.dollar_attr.should == "-321.45"}
|
100
|
+
it{@resource.dollar_attr = BigDecimal("321.45");@resource.dollar_attr.should == "321.45"}
|
100
101
|
end
|
101
102
|
|
102
103
|
describe "#number" do
|
@@ -105,9 +106,10 @@ describe "HasNormalizedAttributes" do
|
|
105
106
|
it{@resource.number_attr = "1\t23\t";@resource.number_attr.should == "123"}
|
106
107
|
it{@resource.number_attr = "";@resource.number_attr.should == ""}
|
107
108
|
it{@resource.number_attr = nil;@resource.number_attr.should == nil}
|
108
|
-
it{@resource.
|
109
|
-
it{@resource.
|
110
|
-
it{@resource.
|
109
|
+
it{@resource.number_attr = 111111.51;@resource.number_attr.should == "111111.51"}
|
110
|
+
it{@resource.number_attr = "(321.45)";@resource.number_attr.should == "-321.45"}
|
111
|
+
it{@resource.number_attr = "-321.45";@resource.number_attr.should == "-321.45"}
|
112
|
+
it{@resource.number_attr = BigDecimal("321.45");@resource.number_attr.should == "321.45"}
|
111
113
|
end
|
112
114
|
|
113
115
|
describe "#percent" do
|