has_normalized_attributes 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,15 +14,19 @@ module HasNormalizedAttributes
14
14
  #instance methods
15
15
  def self.normalizations(*args)
16
16
  args.each do |arg|
17
- reg_exp = HasNormalizedAttributes.const_get(arg.upcase)
18
17
  define_method "normalize_#{arg}" do
19
- self && is_a?(String) && match(reg_exp) ? gsub!(reg_exp,'') : self
18
+ if arg == :strip
19
+ self ? self.strip! : self
20
+ else
21
+ reg_exp = HasNormalizedAttributes.const_get(arg.upcase)
22
+ self && is_a?(String) && match(reg_exp) ? gsub!(reg_exp,'') : self
23
+ end
20
24
  end
21
25
  end
22
26
  end
23
27
 
24
28
  #loading all methods dynamically
25
- normalizations :phone, :zipcode, :ssn, :taxid, :dollar, :number, :percent, :spaces
29
+ normalizations :phone, :zipcode, :ssn, :taxid, :dollar, :number, :percent, :spaces, :strip
26
30
 
27
31
 
28
32
  module ClassMethods
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module HasNormalizedAttributes
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/spec/db/schema.rb CHANGED
@@ -9,6 +9,7 @@ ActiveRecord::Schema.define(:version => 0) do
9
9
  t.string "number_attr"
10
10
  t.string "percent_attr"
11
11
  t.string "spaces_attr"
12
+ t.string "strip_attr"
12
13
  end
13
14
 
14
15
  end
data/spec/db/test.sqlite3 CHANGED
Binary file
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  class Resource < ActiveRecord::Base
4
4
  has_normalized_attributes :phone_attr => :phone, :zipcode_attr => :zipcode, :ssn_attr => :ssn,
5
5
  :dollar_attr => :dollar, :taxid_attr => :taxid, :number_attr => :number,
6
- :percent_attr => :percent, :spaces_attr => :spaces
6
+ :percent_attr => :percent, :spaces_attr => :spaces, :strip_attr => :strip
7
7
  end
8
8
 
9
9
  describe "HasNormalizedAttributes" do
@@ -111,5 +111,12 @@ describe "HasNormalizedAttributes" do
111
111
  it{@resource.spaces_attr = nil;@resource.spaces_attr.should == nil}
112
112
  end
113
113
 
114
+ describe "#strip" do
115
+ it{@resource.strip_attr = "text "; @resource.strip_attr.should == "text"}
116
+ it{@resource.strip_attr = " text"; @resource.strip_attr.should == "text"}
117
+ it{@resource.strip_attr = " text "; @resource.strip_attr.should == "text"}
118
+ it{@resource.strip_attr = " some text"; @resource.strip_attr.should == "some text"}
119
+ it{@resource.strip_attr = " some text "; @resource.strip_attr.should == "some text"}
120
+ end
114
121
 
115
122
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: has_normalized_attributes
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.2
5
+ version: 0.0.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Ginavan