phone 0.9.9 → 0.9.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE CHANGED
@@ -1,4 +1,5 @@
1
1
  Copyright (c) 2010 Tomislav Car
2
+ Modifications copyright (c) 2010 Todd Eichel for Fooala, Inc.
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of
4
5
  this software and associated documentation files (the "Software"), to deal in
@@ -79,7 +79,10 @@ You can add your own custom named formats like so:
79
79
 
80
80
  = TODO
81
81
  Parse testing for different countries. Currently tested on: US, South Africa, Croatia, Slovenia, Hungary, Serbia,
82
- Bosnia and Herzegovina, Germany.
82
+ Bosnia and Herzegovina, Germany, France.
83
83
 
84
84
  = Author
85
85
  Copyright © 2010 Tomislav Car, Infinum
86
+
87
+ Modifications copyright © 2010 Todd Eichel for Fooala, Inc.
88
+
@@ -525,6 +525,7 @@
525
525
  :char_3_code: FR
526
526
  :name: France
527
527
  :international_dialing_prefix: "0"
528
+ :area_code: "[1-6,8-9]"
528
529
  "995":
529
530
  :country_code: "995"
530
531
  :national_dialing_prefix: 8*
@@ -9,8 +9,8 @@
9
9
  # Phone.default_country_code
10
10
  # Phone.default_area_code
11
11
  #
12
- require 'active_support'
13
- require File.join(File.dirname(__FILE__), 'country')
12
+ require 'active_support/core_ext' # for Class#cattr_accessor, String#present?
13
+ require File.join(File.dirname(__FILE__), 'phone_country')
14
14
  class Phone
15
15
  NUMBER = '([^0][0-9]{1,7})$'
16
16
  DEFAULT_AREA_CODE = '[2-9][0-8][0-9]' # USA
@@ -53,7 +53,7 @@ class Phone
53
53
  # the format of the string is detect automatically (from FORMATS)
54
54
  def self.parse(string, options={})
55
55
  if string.present?
56
- Country.load
56
+ PhoneCountry.load
57
57
  string = normalize(string)
58
58
 
59
59
  options[:country_code] ||= self.default_country_code
@@ -83,7 +83,7 @@ class Phone
83
83
  string = string.gsub(country.country_code_regexp, '0')
84
84
  else
85
85
  if options[:country_code]
86
- country = Country.find_by_country_code options[:country_code]
86
+ country = PhoneCountry.find_by_country_code options[:country_code]
87
87
  end
88
88
  end
89
89
 
@@ -113,7 +113,7 @@ class Phone
113
113
  def self.detect_country(string)
114
114
  detected_country = nil
115
115
  # find if the number has a country code
116
- Country.all.each_pair do |country_code, country|
116
+ PhoneCountry.all.each_pair do |country_code, country|
117
117
  if string =~ country.country_code_regexp
118
118
  detected_country = country
119
119
  end
@@ -1,15 +1,16 @@
1
- require 'active_support'
2
- class Country < Struct.new(:name, :country_code, :char_2_code, :area_code)
1
+ require 'active_support/core_ext' # for Class#cattr_accessor
2
+
3
+ class PhoneCountry < Struct.new(:name, :country_code, :char_2_code, :area_code)
3
4
  cattr_accessor :all
4
5
 
5
6
  def self.load
6
7
  return @@all if @@all.present?
7
8
 
8
- data_file = File.join(File.dirname(__FILE__), '..', 'data', 'countries.yml')
9
+ data_file = File.join(File.dirname(__FILE__), '..', 'data', 'phone_countries.yml')
9
10
 
10
11
  @@all = {}
11
12
  YAML.load(File.read(data_file)).each_pair do |key, c|
12
- @@all[key] = Country.new(c[:name], c[:country_code], c[:char_2_code], c[:area_code])
13
+ @@all[key] = PhoneCountry.new(c[:name], c[:country_code], c[:char_2_code], c[:area_code])
13
14
  end
14
15
  @@all
15
16
  end
@@ -1,6 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/test_helper'
2
2
 
3
- class CountryTest < Test::Unit::TestCase
3
+ class PhoneCountryTest < Test::Unit::TestCase
4
4
  def test_parse_germany_local
5
5
  pn = Phone.parse('+49 714 1605832')
6
6
 
@@ -105,4 +105,20 @@ class CountryTest < Test::Unit::TestCase
105
105
  assert_equal pn.area_code, '800'
106
106
  assert_equal pn.number, '123321'
107
107
  end
108
+
109
+ def test_parse_france_local
110
+ pn = Phone.parse('+33 4 75 06 07 07')
111
+
112
+ assert_equal pn.country_code, '33'
113
+ assert_equal pn.area_code, '4'
114
+ assert_equal pn.number, '75060707'
115
+ end
116
+
117
+ def test_parse_france_mobile
118
+ pn = Phone.parse('+33 6 11 22 33 44')
119
+
120
+ assert_equal pn.country_code, '33'
121
+ assert_equal pn.area_code, '6'
122
+ assert_equal pn.number, '11223344'
123
+ end
108
124
  end
File without changes
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.9
4
+ version: 0.9.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomislav Car
8
+ - Todd Eichel
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2010-01-04 00:00:00 +01:00
13
+ date: 2010-03-08 00:00:00 +01:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -23,7 +24,9 @@ dependencies:
23
24
  version: "0"
24
25
  version:
25
26
  description: Phone number parsing, validation and formatting.
26
- email: tomislav@infinum.hr
27
+ email:
28
+ - tomislav@infinum.hr
29
+ - todd@toddeichel.com
27
30
  executables: []
28
31
 
29
32
  extensions: []
@@ -34,11 +37,11 @@ extra_rdoc_files:
34
37
  files:
35
38
  - Readme.rdoc
36
39
  - LICENSE
37
- - data/countries.yml
40
+ - data/phone_countries.yml
38
41
  - lib/phone.rb
39
- - lib/country.rb
40
- - test/phone.rb
41
- - test/country.rb
42
+ - lib/phone_country.rb
43
+ - test/phone_test.rb
44
+ - test/phone_country_test.rb
42
45
  - test/test_helper.rb
43
46
  has_rdoc: true
44
47
  homepage: http://github.com/carr/phone
@@ -72,6 +75,6 @@ signing_key:
72
75
  specification_version: 3
73
76
  summary: Phone number parsing, validation and formatting
74
77
  test_files:
75
- - test/phone.rb
76
- - test/country.rb
78
+ - test/phone_test.rb
79
+ - test/phone_country_test.rb
77
80
  - test/test_helper.rb