countries-phone_numbers 1.0.2 → 1.0.3
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.
- checksums.yaml +4 -4
- data/lib/countries/phone_numbers/extensions.rb +6 -17
- data/lib/countries/phone_numbers/version.rb +1 -1
- data/spec/countries/country_spec.rb +5 -23
- data/spec/countries/phone_numbers_spec.rb +4 -25
- data/spec/spec_helper.rb +8 -1
- data/spec/support/acts_like_a_phone_number_finder.rb +33 -0
- data/spec/support/acts_like_a_phone_number_formatter.rb +20 -0
- data/spec/test_data.yaml +0 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: adc5cf4e2bbdf410f395c091ab9eb5ed0019cb6d
|
|
4
|
+
data.tar.gz: 91f80213099c41d8a05ff0b46cbaacd8602a5dcc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8f6fe4700f0c6077957574e989866c7b53a9091594652e0eed78904f90ca13794e52615a4a3a5ec88c693bd2cc00523e38b739c85831ec2a531eb29ac641938a
|
|
7
|
+
data.tar.gz: 03718c0520e2d9c2673d5a24cc5db31706b8e47eba7f7142385e816b446303a12cd350f4096d7a8ead26ae63cd4c150f5f5e336f9464af4bde6d6fbd469b6a92
|
|
@@ -4,23 +4,12 @@ module Countries::PhoneNumbers::Extensions
|
|
|
4
4
|
base.extend ClassMethods
|
|
5
5
|
end
|
|
6
6
|
|
|
7
|
-
def format_phone_number( number, options={} )
|
|
8
|
-
Phony.formatted( Phony.normalize( number ), options )
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
def format_local_phone_number( number, options={} )
|
|
12
|
-
format_phone_number( number, {format: :local}.merge(options) )
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def format_international_phone_number( number, options={} )
|
|
16
|
-
format_phone_number( number, {format: :international}.merge(options) )
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def format_national_phone_number( number, options={} )
|
|
20
|
-
format_phone_number( number, {format: :national}.merge(options) )
|
|
21
|
-
end
|
|
22
|
-
|
|
23
7
|
module ClassMethods
|
|
8
|
+
|
|
9
|
+
def plausible_phone_number?( number )
|
|
10
|
+
Phony.plausible?( number )
|
|
11
|
+
end
|
|
12
|
+
|
|
24
13
|
def normalize_phone_number( number )
|
|
25
14
|
Phony.normalize( number )
|
|
26
15
|
end
|
|
@@ -60,7 +49,7 @@ module Countries::PhoneNumbers::Extensions
|
|
|
60
49
|
##
|
|
61
50
|
# Find the first country by the given telephone number. Returns the country object itself.
|
|
62
51
|
def find_country_by_phone_number( number )
|
|
63
|
-
found =
|
|
52
|
+
found = find_all_countries_by_phone_number(number)
|
|
64
53
|
found.nil? ? nil : found.first
|
|
65
54
|
end
|
|
66
55
|
|
|
@@ -1,30 +1,12 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'countries/phone_numbers/ext_finders'
|
|
3
|
+
require 'countries/phone_numbers/ext_formatters'
|
|
3
4
|
|
|
4
|
-
describe ISO3166::Country
|
|
5
|
-
subject { Country }
|
|
5
|
+
describe ISO3166::Country do
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
it 'ignores bogus phone numbers (single digit)' do
|
|
9
|
-
subject.find_country_by_phone_number( '5' ).should == nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Test another bogus phone number
|
|
13
|
-
it 'ignores bogus phone numbers (text)' do
|
|
14
|
-
subject.find_country_by_phone_number( 'abc' ).should == nil
|
|
15
|
-
end
|
|
7
|
+
subject { Country }
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
numbers.each do |number|
|
|
20
|
-
it "recognises #{number} as #{alpha2.to_s}" do
|
|
21
|
-
subject.find_country_by_phone_number(number).should_not be_nil
|
|
22
|
-
subject.find_country_by_phone_number(number).alpha2.should == alpha2.to_s
|
|
23
|
-
end
|
|
24
|
-
it "returns only one country for #{number}" do
|
|
25
|
-
subject.find_all_countries_by_phone_number(number).should have(1).country
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
9
|
+
it_behaves_like 'a phone number finder'
|
|
10
|
+
it_behaves_like 'a phone number formatter'
|
|
29
11
|
|
|
30
12
|
end
|
|
@@ -1,32 +1,11 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
require 'countries/phone_numbers'
|
|
3
3
|
|
|
4
|
-
describe Countries::PhoneNumbers
|
|
5
|
-
subject { Countries::PhoneNumbers }
|
|
6
|
-
|
|
7
|
-
# Test a bogus phone number
|
|
8
|
-
it 'ignores bogus phone numbers (single digit)' do
|
|
9
|
-
subject.find_country_by_phone_number( '5' ).should == nil
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# Test another bogus phone number
|
|
13
|
-
it 'ignores bogus phone numbers (text)' do
|
|
14
|
-
subject.find_country_by_phone_number( 'abc' ).should == nil
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
# Test all data given in the 'TEST' block above
|
|
18
|
-
TEST_DATA.each do |alpha2, numbers|
|
|
19
|
-
numbers.each do |number|
|
|
20
|
-
it "recognises #{number} as #{alpha2.to_s}" do
|
|
21
|
-
subject.find_country_by_phone_number(number).should_not be_nil
|
|
22
|
-
subject.find_country_by_phone_number(number).alpha2.should == alpha2.to_s
|
|
23
|
-
end
|
|
24
|
-
it "returns only one country for #{number}" do
|
|
25
|
-
subject.find_all_countries_by_phone_number(number).should have(1).country
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
4
|
+
describe Countries::PhoneNumbers do
|
|
29
5
|
|
|
6
|
+
it_behaves_like 'a phone number finder'
|
|
7
|
+
it_behaves_like 'a phone number formatter'
|
|
8
|
+
|
|
30
9
|
Countries::PhoneNumbers.unresolved_country_codes.each do |country_code, countries|
|
|
31
10
|
pending "Need to resolve CC: #{country_code} for #{countries.join(', ')}."
|
|
32
11
|
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -10,6 +10,10 @@ require 'countries/phone_numbers'
|
|
|
10
10
|
require 'yaml'
|
|
11
11
|
TEST_DATA = YAML.load_file( File.join( File.dirname(__FILE__), 'test_data.yaml' ) )
|
|
12
12
|
|
|
13
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
|
14
|
+
# in spec/support/ and its subdirectories.
|
|
15
|
+
Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f}
|
|
16
|
+
|
|
13
17
|
# This file was generated by the `rspec --init` command. Conventionally, all
|
|
14
18
|
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
|
15
19
|
# Require this file using `require "spec_helper"` to ensure that it is only
|
|
@@ -18,8 +22,11 @@ TEST_DATA = YAML.load_file( File.join( File.dirname(__FILE__), 'test_data.yaml'
|
|
|
18
22
|
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
|
19
23
|
RSpec.configure do |config|
|
|
20
24
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
|
25
|
+
|
|
26
|
+
# Filter
|
|
27
|
+
config.filter_run :focus => true
|
|
28
|
+
config.filter_run_excluding :skip
|
|
21
29
|
config.run_all_when_everything_filtered = true
|
|
22
|
-
config.filter_run :focus
|
|
23
30
|
|
|
24
31
|
# Run specs in random order to surface order dependencies. If you find an
|
|
25
32
|
# order dependency and want to debug it, you can fix the order by providing
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
shared_examples 'a phone number finder' do |factory|
|
|
2
|
+
|
|
3
|
+
# Test a bogus phone number
|
|
4
|
+
it 'ignores bogus phone numbers (single digit)' do
|
|
5
|
+
subject.find_country_by_phone_number( '5' ).should == nil
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
# Test another bogus phone number
|
|
9
|
+
it 'ignores bogus phone numbers (text)' do
|
|
10
|
+
subject.find_country_by_phone_number( 'abc' ).should == nil
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Test all data given in the 'TEST' block (defined in the spec helper)
|
|
14
|
+
TEST_DATA.each do |alpha2, numbers|
|
|
15
|
+
numbers.each do |number|
|
|
16
|
+
|
|
17
|
+
it "recognises #{number} as #{alpha2}" do
|
|
18
|
+
subject.find_country_by_phone_number(number).should_not be_nil
|
|
19
|
+
subject.find_country_by_phone_number(number).alpha2.should == alpha2.to_s
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "returns only one country for #{number}" do
|
|
23
|
+
subject.find_all_countries_by_phone_number(number).should have(1).country
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "recognises #{number} as plausible" do
|
|
27
|
+
subject.plausible_phone_number?(number).should eq(Phony.plausible?(number))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
end # number
|
|
31
|
+
end # test data
|
|
32
|
+
|
|
33
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
shared_examples 'a phone number formatter' do |factory|
|
|
2
|
+
|
|
3
|
+
# Test all data given in the 'TEST' block (defined in the spec helper)
|
|
4
|
+
TEST_DATA.each do |alpha2, numbers|
|
|
5
|
+
numbers.each do |number|
|
|
6
|
+
|
|
7
|
+
it "formats #{number} internationally" do
|
|
8
|
+
expected = Phony.format(Phony.normalize(number), format: :international)
|
|
9
|
+
subject.format_international_phone_number(number).should eq(expected)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "formats #{number} nationally" do
|
|
13
|
+
expected = Phony.format(Phony.normalize(number), format: :national)
|
|
14
|
+
subject.format_national_phone_number(number).should eq(expected)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end # number
|
|
18
|
+
end # test data
|
|
19
|
+
|
|
20
|
+
end
|
data/spec/test_data.yaml
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: countries-phone_numbers
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0.
|
|
4
|
+
version: 1.0.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ian Lloyd
|
|
@@ -137,6 +137,8 @@ files:
|
|
|
137
137
|
- spec/countries/phone_numbers/detector_factory_spec.rb
|
|
138
138
|
- spec/countries/phone_numbers_spec.rb
|
|
139
139
|
- spec/spec_helper.rb
|
|
140
|
+
- spec/support/acts_like_a_phone_number_finder.rb
|
|
141
|
+
- spec/support/acts_like_a_phone_number_formatter.rb
|
|
140
142
|
- spec/test_data.yaml
|
|
141
143
|
homepage: http://github.com/illoyd/countries-phone_numbers
|
|
142
144
|
licenses:
|
|
@@ -167,4 +169,6 @@ test_files:
|
|
|
167
169
|
- spec/countries/phone_numbers/detector_factory_spec.rb
|
|
168
170
|
- spec/countries/phone_numbers_spec.rb
|
|
169
171
|
- spec/spec_helper.rb
|
|
172
|
+
- spec/support/acts_like_a_phone_number_finder.rb
|
|
173
|
+
- spec/support/acts_like_a_phone_number_formatter.rb
|
|
170
174
|
- spec/test_data.yaml
|