phone_number 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  = phone_number
2
2
 
3
- http://github.com/midas/guilded
3
+ http://github.com/midas/phone_number
4
4
 
5
5
  == DESCRIPTION
6
6
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -1,17 +1,17 @@
1
1
  module PhoneNumber
2
2
  class Number
3
- MATCH_REGEX = /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/
4
-
3
+ REGEX = /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/
4
+ INVALID_MESSAGE = "invalid format, try something like: 111-111-1111"
5
5
  attr_reader :country_code, :area_code, :subscriber_number_prefix, :subscriber_number_postfix, :extension
6
6
 
7
7
  def initialize( number )
8
- if number.is_a?( String ) && m = number.match( /^(\d{1,2})(\d{3})(\d{3})(\d{4})x?(\d*)$/ )
8
+ if number.is_a?( String ) && m = number.match( REGEX )
9
9
  @country_code, @area_code, @subscriber_number_prefix, @subscriber_number_postfix, @extension = m[1], m[2], m[3], m[4], m[5]
10
10
  elsif number.is_a?( Hash )
11
11
  @country_code, @area_code, @subscriber_number_prefix, @subscriber_number_postfix, @extension = number[:country_code], number[:area_code], number[:subscriber_number_prefix], number[:subscriber_number_postfix], number[:extension]
12
12
  end
13
13
 
14
- @@pattern_map = {
14
+ @pattern_map = {
15
15
  /%c/ => (@country_code || '').gsub( /0/, '' ) || "",
16
16
  /%C/ => @country_code || "",
17
17
  /%a/ => @area_code || "",
@@ -31,12 +31,14 @@ module PhoneNumber
31
31
 
32
32
  def self.parse( number )
33
33
  number.gsub!( / x /, 'x' )
34
- if m = number.match( MATCH_REGEX )
34
+ if m = number.match( REGEX )
35
35
  cntry_cd = m[1].size == 2 ? m[1] : "0#{m[1]}"
36
36
  cntry_cd = '01' if cntry_cd.nil? || cntry_cd.empty? || cntry_cd == '0'
37
- Number.new( :country_code => cntry_cd, :area_code => m[2], :subscriber_number_prefix => m[3], :subscriber_number_postfix => m[4],
38
- :extension => m[5] )
37
+ return Number.new( :country_code => cntry_cd, :area_code => m[2], :subscriber_number_prefix => m[3],
38
+ :subscriber_number_postfix => m[4], :extension => m[5] )
39
39
  end
40
+
41
+ Number.new( {} )
40
42
  end
41
43
 
42
44
  def empty?
@@ -56,7 +58,7 @@ module PhoneNumber
56
58
  return '' if self.empty?
57
59
  to_return = pattern.is_a?( Symbol ) ? @@patterns[pattern] : pattern
58
60
  to_return = @@patterns[:us_short] if to_return.empty?
59
- @@pattern_map.each { |pat, replacement| to_return = to_return.gsub( pat, replacement ) }
61
+ @pattern_map.each { |pat, replacement| to_return = to_return.gsub( pat, replacement ) }
60
62
  to_return.strip
61
63
  end
62
64
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{phone_number}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.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)"]
@@ -1,10 +1,10 @@
1
- require File.expand_path( File.dirname(__FILE__) + '/../spec_helper' )
1
+ require 'spec_helper'
2
2
  require File.expand_path( File.dirname(__FILE__) + '/number_parsing_shared_spec' )
3
3
 
4
4
 
5
5
  describe "PhoneNumber::Number" do
6
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*)$/
7
+ PhoneNumber::Number::REGEX.should == /^\+?(\d{0,2})[ \.\-]?\(?(\d{3})\)?[ \.\-]?(\d{3})[ \.\-]?(\d{4})[ x]?(\d*)$/
8
8
  end
9
9
 
10
10
  describe "when initializing from a raw string with an extension" do
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone_number
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 31
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 1.1.0
10
+ version: 1.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - C. Jason Harrelson (midas)