has_normalized_attributes 0.0.6 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e37778b8ae93697c06b768b3f52735fe2b64897
4
- data.tar.gz: 8e03c4140fb42e08d54fc997163b521ec2efbc68
3
+ metadata.gz: 91dc221ce7007d6265c70324eb766a71b7d094a0
4
+ data.tar.gz: f3d16b28f11791f70d98356f950b2fe346c8db2f
5
5
  SHA512:
6
- metadata.gz: e4e44f282445e6d70d068b823fe24428db232622d2df8a3c96546a3e727493e5c39b30ca8225516246d8268f6b48f5635d08b9c9ac8a2ba87cd581186afc7f8b
7
- data.tar.gz: b20e70e100b07c2b797037dae4d53372f33d3a4e19a126c88d88937bda337f190842733ec5f033568cfebd63c957951b742fa63c502d1836384c1af5f494639c
6
+ metadata.gz: d1fe3bacd965a7ef3880ccb64d38081413c5ccba78d3448a8babffd0be09219992d58f8dc619ab11d0cef93df74e5af3e3fa42257bd38946465adac08c7dbfc3
7
+ data.tar.gz: 211acf70d9871c0d78bdaa4c053d347970370256580831a84a3df63a7588016788d016475774057855a8a3afb0d9b1b458e3a02fff198eb3c5e8f25964822b95
data/.travis.yml CHANGED
@@ -1,5 +1,2 @@
1
- rvm:
2
- - 1.9.3
3
- - 1.9.2
4
-
1
+ rvm: "2.1.2"
5
2
  script: rake spec
@@ -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().tap do |result|
14
- result.sub! /\A\((.*)\)\Z/, '-\1' if result.respond_to?(:sub!)
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! : self
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!(reg_exp,'') : self
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 value
64
+ super normalized_value
64
65
  end
65
66
  end
66
67
 
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HasNormalizedAttributes
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.8"
3
3
  end
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.dollar_attr = 111111.51;@resource.dollar_attr.should == "111111.51"}
109
- it{@resource.dollar_attr = "(321.45)";@resource.dollar_attr.should == "-321.45"}
110
- it{@resource.dollar_attr = "-321.45";@resource.dollar_attr.should == "-321.45"}
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: has_normalized_attributes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Ginavan