phone_number 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
@@ -1,5 +1,7 @@
1
1
  module PhoneNumber
2
2
  class Number
3
+ MATCH_REGEX = /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/
4
+
3
5
  attr_reader :country_code, :area_code, :subscriber_number_prefix, :subscriber_number_postfix, :extension
4
6
 
5
7
  def initialize( number )
@@ -10,18 +12,18 @@ module PhoneNumber
10
12
  end
11
13
 
12
14
  @@pattern_map = {
13
- /%c/ => (@country_code || '').gsub( /0/, '' ) || "",
14
- /%C/ => @country_code || "",
15
- /%a/ => @area_code || "",
16
- /%m/ => @subscriber_number_prefix || "",
17
- /%p/ => @subscriber_number_postfix || "",
18
- /%x/ => @extension || ""
15
+ /%c/ => (@country_code || '').gsub( /0/, '' ) || "",
16
+ /%C/ => @country_code || "",
17
+ /%a/ => @area_code || "",
18
+ /%m/ => @subscriber_number_prefix || "",
19
+ /%p/ => @subscriber_number_postfix || "",
20
+ /%x/ => @extension || ""
19
21
  }
20
22
 
21
23
  @@patterns = {
22
- :us => "%c (%a) %m-%p x %x",
23
- :us_short => "(%a) %m-%p",
24
- :nanp_short => "(%a) %m-%p"
24
+ :us => "%c (%a) %m-%p x %x",
25
+ :us_short => "(%a) %m-%p",
26
+ :nanp_short => "(%a) %m-%p"
25
27
  }
26
28
 
27
29
  self.freeze
@@ -29,7 +31,7 @@ module PhoneNumber
29
31
 
30
32
  def self.parse( number )
31
33
  number.gsub!( / x /, 'x' )
32
- if m = number.match( /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/ )
34
+ if m = number.match( MATCH_REGEX )
33
35
  cntry_cd = m[1].size == 2 ? m[1] : "0#{m[1]}"
34
36
  cntry_cd = '01' if cntry_cd.nil? || cntry_cd.empty? || cntry_cd == '0'
35
37
  Number.new( :country_code => cntry_cd, :area_code => m[2], :subscriber_number_prefix => m[3], :subscriber_number_postfix => m[4],
@@ -62,8 +64,6 @@ module PhoneNumber
62
64
  parse( number )
63
65
  end
64
66
 
65
- private
66
-
67
67
  def raw
68
68
  ext = (@extension.nil? || @extension.empty?) ? "" : "x#{@extension}"
69
69
  "#{@country_code}#{@area_code}#{@subscriber_number_prefix}#{@subscriber_number_postfix}#{ext}"
data/phone_number.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{phone_number}
8
- s.version = "1.0.0"
8
+ s.version = "1.1.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["C. Jason Harrelson (midas)"]
12
- s.date = %q{2009-12-25}
12
+ s.date = %q{2010-11-10}
13
13
  s.description = %q{Encapsulates the composed of pattern for phone numbers into any easy to use library.}
14
14
  s.email = %q{jason@lookforwardenterprises.com}
15
15
  s.extra_rdoc_files = [
@@ -40,7 +40,7 @@ Gem::Specification.new do |s|
40
40
  s.homepage = %q{http://github.com/midas/phone_number}
41
41
  s.rdoc_options = ["--charset=UTF-8"]
42
42
  s.require_paths = ["lib"]
43
- s.rubygems_version = %q{1.3.5}
43
+ s.rubygems_version = %q{1.3.7}
44
44
  s.summary = %q{Encapsulates the composed of pattern for phone numbers into any easy to use library.}
45
45
  s.test_files = [
46
46
  "spec/phone_number/number_parsing_shared_spec.rb",
@@ -53,7 +53,7 @@ Gem::Specification.new do |s|
53
53
  current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
54
54
  s.specification_version = 3
55
55
 
56
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
56
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
57
57
  s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
58
58
  s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
59
59
  else
@@ -3,6 +3,10 @@ require File.expand_path( File.dirname(__FILE__) + '/number_parsing_shared_spec'
3
3
 
4
4
 
5
5
  describe "PhoneNumber::Number" do
6
+ it "should agree that the MATCH_REGEX is /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/" do
7
+ PhoneNumber::Number::MATCH_REGEX.should == /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/
8
+ end
9
+
6
10
  describe "when initializing from a raw string with an extension" do
7
11
  before :each do
8
12
  @instance = PhoneNumber::Number.new( '012345678901x111' )
@@ -20,19 +24,50 @@ describe "PhoneNumber::Number" do
20
24
  end
21
25
 
22
26
  describe "when being set equal to a string if correctly parsing" do
23
- numbers = ['012345678901', '+012345678901', '12345678901', '2345678901', '01-234-567-8901', '01.234.567.8901', '01 234 567 8901', '+01-234-567-8901',
24
- '+01.234.567.8901', '+01 234 567 8901', '1-234-567-8901', '1.234.567.8901', '1 234 567 8901', '+1-234-567-8901', '+1.234.567.8901', '+1 234 567 8901',
25
- '1 (234) 567-8901', '(234) 567-8901', '1 (234) 567.8901', '(234) 567.8901', '(234) 567 8901', '(234) 5678901', '(234)5678901', '1(234)5678901',
26
- '01(234)5678901', '+1(234)5678901', '+01(234)5678901' ]
27
-
27
+ numbers = ['012345678901',
28
+ '+012345678901',
29
+ '12345678901',
30
+ '2345678901',
31
+ '01-234-567-8901',
32
+ '01.234.567.8901',
33
+ '01 234 567 8901',
34
+ '+01-234-567-8901',
35
+ '+01.234.567.8901',
36
+ '+01 234 567 8901',
37
+ '1-234-567-8901',
38
+ '1.234.567.8901',
39
+ '1 234 567 8901',
40
+ '+1-234-567-8901',
41
+ '+1.234.567.8901',
42
+ '+1 234 567 8901',
43
+ '1 (234) 567-8901',
44
+ '(234) 567-8901',
45
+ '1 (234) 567.8901',
46
+ '(234) 567.8901',
47
+ '(234) 567 8901',
48
+ '(234) 5678901',
49
+ '(234)5678901',
50
+ '1(234)5678901',
51
+ '01(234)5678901',
52
+ '+1(234)5678901',
53
+ '+01(234)5678901']
54
+
28
55
  numbers.each do |number|
29
- describe "'#{number}'" do
56
+ describe "when parsing '#{number}'" do
30
57
  before :each do
31
58
  @instance = PhoneNumber::Number.parse( number )
32
59
  end
33
60
 
34
61
  it_should_behave_like "The phone number 1-234-567-8901"
35
62
  end
63
+
64
+ # describe "when initializing '#{number}'" do
65
+ # before :each do
66
+ # @instance = PhoneNumber::Number.new( number )
67
+ # end
68
+ #
69
+ # it_should_behave_like "The phone number 1-234-567-8901"
70
+ # end
36
71
  end
37
72
 
38
73
  numbers.map{ |n| n + 'x111' }.each do |number|
@@ -77,7 +112,7 @@ describe "PhoneNumber::Number" do
77
112
  @instance.to_s( :us_short ).should eql( @instance.to_s )
78
113
  end
79
114
  end
80
-
115
+
81
116
  it "should agree that a newly instantiated phone number is empty" do
82
117
  PhoneNumber::Number.new( nil ).empty?.should be_true
83
118
  end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone_number
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ hash: 19
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 0
10
+ version: 1.1.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - C. Jason Harrelson (midas)
@@ -9,29 +15,40 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-12-25 00:00:00 -06:00
18
+ date: 2010-11-10 00:00:00 -06:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: activerecord
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
20
26
  requirements:
21
27
  - - ">="
22
28
  - !ruby/object:Gem::Version
29
+ hash: 5
30
+ segments:
31
+ - 2
32
+ - 3
23
33
  version: "2.3"
24
- version:
34
+ type: :runtime
35
+ version_requirements: *id001
25
36
  - !ruby/object:Gem::Dependency
26
37
  name: rspec
27
- type: :development
28
- version_requirement:
29
- version_requirements: !ruby/object:Gem::Requirement
38
+ prerelease: false
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
30
41
  requirements:
31
42
  - - ">="
32
43
  - !ruby/object:Gem::Version
44
+ hash: 13
45
+ segments:
46
+ - 1
47
+ - 2
48
+ - 9
33
49
  version: 1.2.9
34
- version:
50
+ type: :development
51
+ version_requirements: *id002
35
52
  description: Encapsulates the composed of pattern for phone numbers into any easy to use library.
36
53
  email: jason@lookforwardenterprises.com
37
54
  executables: []
@@ -71,21 +88,27 @@ rdoc_options:
71
88
  require_paths:
72
89
  - lib
73
90
  required_ruby_version: !ruby/object:Gem::Requirement
91
+ none: false
74
92
  requirements:
75
93
  - - ">="
76
94
  - !ruby/object:Gem::Version
95
+ hash: 3
96
+ segments:
97
+ - 0
77
98
  version: "0"
78
- version:
79
99
  required_rubygems_version: !ruby/object:Gem::Requirement
100
+ none: false
80
101
  requirements:
81
102
  - - ">="
82
103
  - !ruby/object:Gem::Version
104
+ hash: 3
105
+ segments:
106
+ - 0
83
107
  version: "0"
84
- version:
85
108
  requirements: []
86
109
 
87
110
  rubyforge_project:
88
- rubygems_version: 1.3.5
111
+ rubygems_version: 1.3.7
89
112
  signing_key:
90
113
  specification_version: 3
91
114
  summary: Encapsulates the composed of pattern for phone numbers into any easy to use library.