phone 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34e8a065d7c2af3086436c2a7d6946cd6f9e2d02
4
- data.tar.gz: 9d543d715d22246f7b150c6a7f8b2c21f8a3d110
3
+ metadata.gz: f34c77402ea12b6fafbda205f46bb897b0996c66
4
+ data.tar.gz: f29f3fd69c0f6415ba76d1d16da01279cdc76b8e
5
5
  SHA512:
6
- metadata.gz: 4ff96c2231df0d988f8ec44942704e6169a8afd5c91b1b0db5625b5308b7ee8d06367f9add22898a447b1ed4de71a50c6cd14658158b4f1ba752e74d3ccd8be4
7
- data.tar.gz: 51f4da5b4739af217a419b6a15271d1c5e7436853cbe3062108c99c44a042b6c2c04dd41290672581e93efe8e7b28cad4679516022db75b42e027e227d4a8396
6
+ metadata.gz: c94ec8394ccd7a4485d56caa2e701d147f241745909622b59a08c05e4d91733f01b21088e7c81d53cdb1a55efb5d73926c46f3abe9bf3496ae8d4a8bc9fa1087
7
+ data.tar.gz: 23f8e3d274b53614a54964c87bd7cc09a7ef103d47eccf1d53db75a444a986e6e40d8cf80dc657ed0febb7a0a48ec2a631fab8197b0e7f7a5c9bf6016685235c
@@ -85,6 +85,15 @@ You can add your own custom named formats like so:
85
85
  Phoner::Phone.named_formats[:short] = '%A/%n1-%n2'
86
86
  pn.format(:short) # => 091/512-5486
87
87
 
88
+ == Finding countries by their isocode
89
+ If you don't have the country code, but you know from other sources what country a phone is from, you can retrieve the country using the country isocode (such as 'de', 'es', 'us', ...).
90
+
91
+ if country = Phoner::Country.find_by_country_isocode(user_country_isocode)
92
+ phone_number = Phoner::Phone.parse(user_input, :country_code => country.country_code)
93
+ end
94
+
95
+ You have to remember to run Phoner::Country.load method before though.
96
+
88
97
  = TODO
89
98
  Parse testing for different countries.
90
99
 
@@ -93,6 +102,7 @@ Currently tested on:
93
102
  [BA] Bosnia and Herzegovina
94
103
  [BE] Belgium
95
104
  [DE] Germany
105
+ [ES] Spain
96
106
  [FR] France
97
107
  [GB] United Kingdom
98
108
  [HR] Croatia
@@ -106,11 +116,11 @@ Currently tested on:
106
116
  [ZA] South Africa
107
117
 
108
118
  = Known issues
109
- There's an issue with Germany and area codes.
119
+ There's an issue with Germany and Spanish area codes.
110
120
 
111
121
  = Author
112
122
  Copyright © 2010 Tomislav Car, {Infinum}[http://www.infinumdigital.com]
113
123
 
114
124
  = Contributors
115
- Don Morrison, Michael Squires, Todd Eichel (Fooala, Inc.), chipiga, Etienne Samson, Luke Randall
125
+ Don Morrison, Michael Squires, Todd Eichel (Fooala, Inc.), chipiga, Etienne Samson, Luke Randall, Jakob Hilden, Tieg Zaharia
116
126
 
@@ -572,6 +572,7 @@
572
572
  :char_3_code: ES
573
573
  :name: Spain
574
574
  :international_dialing_prefix: "0"
575
+ :area_code: "6[0-9][0-9]|7[1-9][0-9]|9[0-9][0-9]"
575
576
  "232":
576
577
  :country_code: "232"
577
578
  :national_dialing_prefix: "0"
@@ -1,5 +1,5 @@
1
1
  module Phoner
2
- class Country < Struct.new(:name, :country_code, :char_2_code, :area_code)
2
+ class Country < Struct.new(:name, :country_code, :char_2_code, :char_3_code, :area_code)
3
3
  cattr_accessor :all
4
4
 
5
5
  def self.load
@@ -9,7 +9,7 @@ module Phoner
9
9
 
10
10
  @@all = {}
11
11
  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])
12
+ @@all[key] = Country.new(c[:name], c[:country_code], c[:char_2_code], c[:char_3_code], c[:area_code])
13
13
  end
14
14
  @@all
15
15
  end
@@ -19,12 +19,18 @@ module Phoner
19
19
  end
20
20
 
21
21
  def self.find_by_country_code(code)
22
- @@all[code]
22
+ @@all[code]
23
+ end
24
+
25
+ def self.find_by_country_isocode(isocode)
26
+ if country = @@all.detect{|c|c[1].char_3_code.downcase == isocode}
27
+ country[1]
28
+ end
23
29
  end
24
30
 
25
31
  def country_code_regexp
26
- Regexp.new("^[+]#{country_code}")
32
+ Regexp.new("^[+]#{country_code}")
27
33
  end
28
34
  end
29
35
 
30
- end
36
+ end
@@ -16,7 +16,7 @@ require File.join(File.dirname(__FILE__), 'errors')
16
16
  module Phoner
17
17
  class Phone
18
18
  NUMBER = '([0-9]{1,8})$'
19
- DEFAULT_AREA_CODE = '[2-9][0-8][0-9]' # USA
19
+ DEFAULT_AREA_CODE = '[0-9][0-9][0-9]' # any 3 digits
20
20
 
21
21
  attr_accessor :country_code, :area_code, :number, :extension
22
22
 
@@ -159,7 +159,7 @@ module Phoner
159
159
 
160
160
  # fix string so it's easier to parse, remove extra characters etc.
161
161
  def self.normalize(string_with_number)
162
- string_with_number.gsub("(0)", "").gsub(/[^0-9+]/, '').gsub(/^00/, '+')
162
+ string_with_number.gsub("(0)", "").gsub(/[^0-9+]/, '').gsub(/^00/, '+').gsub(/^\+00/, '+').gsub(/^\+0/, '+')
163
163
  end
164
164
 
165
165
  # pull off anything that look like an extension
@@ -257,4 +257,4 @@ module Phoner
257
257
  return result
258
258
  end
259
259
  end
260
- end
260
+ end
@@ -114,4 +114,12 @@ class PhoneTest < Test::Unit::TestCase
114
114
  pn2 = Phoner::Phone.new '1234567', '91', '385'
115
115
  assert pn1 != pn2
116
116
  end
117
+
118
+ def test_find_by_country_isocode
119
+ Phoner::Country.load
120
+ assert_equal Phoner::Country.find_by_country_isocode('de').country_code, "49"
121
+ assert_equal Phoner::Country.find_by_country_isocode('xx'), nil
122
+ assert_equal Phoner::Country.find_by_country_isocode('bla'), nil
123
+ end
124
+
117
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phone
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tomislav Car