validates_telephone 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,9 +2,9 @@ module ValidatesTelephone
2
2
  module Formatter
3
3
  def self.br(number)
4
4
  return nil if number.nil?
5
- number.gsub(/[\(\)-]/, "") =~ /^(\d{2})(\d{4})(\d{4})$/
5
+ number.gsub(/[\(\)-]/, "") =~ /^(\d{2})(9)?(\d{4})(\d{4})$/
6
6
  return number if $1.nil?
7
- "(#{$1})#{$2}-#{$3}"
7
+ "(#{$1})#{$2}#{$3}-#{$4}"
8
8
  end
9
9
 
10
10
  def self.usa(number)
@@ -18,4 +18,4 @@ module ValidatesTelephone
18
18
  number
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -1,7 +1,7 @@
1
1
  module ValidatesTelephone
2
2
  module Regex
3
3
  def self.br(number)
4
- number =~ /^(\(?\d{2}\)?)(\d{4})-?(\d{4})$/
4
+ number =~ /^(\(?\d{2}\)?)(9)?(\d{4})-?(\d{4})$/
5
5
  end
6
6
 
7
7
  def self.usa(number)
@@ -12,4 +12,4 @@ module ValidatesTelephone
12
12
  number =~ /^(\(\d{2}\))(\d{4})-(\d{4})|(\([^2-9]\d{2}\))(\d{3})-(\d{4})$/
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -14,13 +14,13 @@ module Remarkable
14
14
 
15
15
  def telephone_valid?
16
16
  return allows_value_of("(111)222-3333") if @options[:locale] == :usa
17
- return allows_value_of("(11)2222-3333") if @options[:locale] == :br
17
+ return (allows_value_of("(11)2222-3333") and allows_value_of("(11)91111-1111")) if @options[:locale] == :br
18
18
  allows_value_of("(111)222-3333") and allows_value_of("(11)2222-3333")
19
19
  end
20
20
 
21
21
  def telephone_invalid?
22
22
  return (disallows_value_of("123456") and disallows_value_of("(11)2222-3333")) if @options[:locale] == :usa
23
- return (disallows_value_of("123456") and disallows_value_of("(111)222-3333")) if @options[:locale] == :br
23
+ return (disallows_value_of("123456") and disallows_value_of("(111)222-3333") and disallows_value_of("(11)81111-1111")) if @options[:locale] == :br
24
24
  disallows_value_of("123456")
25
25
  end
26
26
 
@@ -40,4 +40,4 @@ module Remarkable
40
40
  end
41
41
  end
42
42
  end
43
- end
43
+ end
@@ -32,16 +32,16 @@ module Shoulda
32
32
 
33
33
  def disallows_invalid_value
34
34
  return (disallows_value_of("123456") and disallows_value_of("(11)2222-3333")) if @options[:locale] == :usa
35
- return (disallows_value_of("123456") and disallows_value_of("(111)222-3333")) if @options[:locale] == :br
35
+ return (disallows_value_of("123456") and disallows_value_of("(111)222-3333") and disallows_value_of("(11)81111-1111")) if @options[:locale] == :br
36
36
  disallows_value_of("123456")
37
37
  end
38
38
 
39
39
  def allows_valid_value
40
40
  return allows_value_of("(111)222-3333") if @options[:locale] == :usa
41
- return allows_value_of("(11)2222-3333") if @options[:locale] == :br
41
+ return (allows_value_of("(11)2222-3333") and allows_value_of("(11)91111-1111")) if @options[:locale] == :br
42
42
  allows_value_of("(111)222-3333") and allows_value_of("(11)2222-3333")
43
43
  end
44
44
  end
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module ValidatesTelephone
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -14,6 +14,10 @@ describe ValidatesTelephone::Validator do
14
14
  it "12345678910 as number" do
15
15
  ValidatesTelephone::Validator.new('12345678910', :br).should_not be_valid
16
16
  end
17
+
18
+ it "11811111111 as number" do
19
+ ValidatesTelephone::Validator.new('11811111111', :br).should_not be_valid
20
+ end
17
21
  end
18
22
 
19
23
  context "should be valid with" do
@@ -36,12 +40,20 @@ describe ValidatesTelephone::Validator do
36
40
  it "(11)1111-1111 as number" do
37
41
  ValidatesTelephone::Validator.new('(11)1111-1111', :br).should be_valid
38
42
  end
43
+
44
+ it "(11)91111-1111 as number" do
45
+ ValidatesTelephone::Validator.new('(11)91111-1111', :br).should be_valid
46
+ end
39
47
  end
40
48
 
41
49
  context "with a valid value" do
42
50
  it "should return it formatted" do
43
51
  ValidatesTelephone::Validator.new('1111111111', :br).number.should == '(11)1111-1111'
44
52
  end
53
+
54
+ it "should return it formatted(sp format)" do
55
+ ValidatesTelephone::Validator.new('11911111111', :br).number.should == '(11)91111-1111'
56
+ end
45
57
  end
46
58
 
47
59
  context "with an invalid value" do
@@ -142,4 +154,4 @@ describe ValidatesTelephone::Validator do
142
154
  end
143
155
  end
144
156
  end
145
- end
157
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: validates_telephone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-26 00:00:00.000000000 Z
12
+ date: 2012-08-27 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
@@ -168,12 +168,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
168
  - - ! '>='
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
+ segments:
172
+ - 0
173
+ hash: -3480777395687768892
171
174
  required_rubygems_version: !ruby/object:Gem::Requirement
172
175
  none: false
173
176
  requirements:
174
177
  - - ! '>='
175
178
  - !ruby/object:Gem::Version
176
179
  version: '0'
180
+ segments:
181
+ - 0
182
+ hash: -3480777395687768892
177
183
  requirements: []
178
184
  rubyforge_project:
179
185
  rubygems_version: 1.8.24