big-phoney 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{big-phoney}
5
- s.version = "0.1.2"
5
+ s.version = "0.1.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Pat Nakajima", "Brandon Keene"]
@@ -62,8 +62,9 @@ module BigPhoney
62
62
 
63
63
  attr_accessor :country_code, :ext, :number
64
64
 
65
- def initialize(number)
65
+ def initialize(number, options={})
66
66
  @number = number.to_s.strip
67
+ @country_code = options[:country_code]
67
68
  parse_extension
68
69
  parse_country_code
69
70
  end
@@ -21,7 +21,7 @@ module BigPhoney
21
21
  record.errors[attribute] << "must be a valid US phone number"
22
22
  end
23
23
 
24
- if number and not BigPhoney::PhoneNumber.new(number).valid?
24
+ if number and not BigPhoney::PhoneNumber.new(number, :country_code => record.try(:country_code)).valid?
25
25
  if record.errors[attribute].empty?
26
26
  record.errors[attribute] << "is not valid"
27
27
  end
@@ -7,6 +7,11 @@ describe BigPhoney::PhoneNumber do
7
7
  number.should be_valid
8
8
  end
9
9
 
10
+ it "is valid with international numbers" do
11
+ number = BigPhoney::PhoneNumber.new('31624124705')
12
+ number.should be_valid
13
+ end
14
+
10
15
  it "is invalid with wrong country code" do
11
16
  number = BigPhoney::PhoneNumber.new('+29 (484) 123-1234')
12
17
  number.should_not be_valid
@@ -114,6 +119,11 @@ describe BigPhoney::PhoneNumber do
114
119
  BigPhoney::PhoneNumber.assume_us = false
115
120
  end
116
121
 
122
+ it "can be passed a country code" do
123
+ phone = BigPhoney::PhoneNumber.new('932211000', :country_code => "34")
124
+ phone.country_code.should == "34"
125
+ end
126
+
117
127
  it "parses 1 digit country code" do
118
128
  phone = BigPhoney::PhoneNumber.new('74841231234')
119
129
  phone.country_code.should == '7'
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: big-phoney
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
9
+ - 3
10
+ version: 0.1.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Pat Nakajima