phony 1.9.0 → 2.19.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/README.textile +64 -112
  3. data/lib/phony/config.rb +91 -0
  4. data/lib/phony/countries/argentina.rb +355 -0
  5. data/lib/phony/countries/austria.rb +56 -22
  6. data/lib/phony/countries/bangladesh.rb +57 -0
  7. data/lib/phony/countries/belarus.rb +133 -0
  8. data/lib/phony/countries/brazil.rb +101 -95
  9. data/lib/phony/countries/cambodia.rb +131 -0
  10. data/lib/phony/countries/china.rb +13 -6
  11. data/lib/phony/countries/croatia.rb +23 -0
  12. data/lib/phony/countries/georgia.rb +94 -0
  13. data/lib/phony/countries/germany.rb +66 -42
  14. data/lib/phony/countries/guinea.rb +46 -0
  15. data/lib/phony/countries/india.rb +50 -0
  16. data/lib/phony/countries/indonesia.rb +55 -0
  17. data/lib/phony/countries/ireland.rb +35 -28
  18. data/lib/phony/countries/italy.rb +272 -166
  19. data/lib/phony/countries/japan.rb +468 -0
  20. data/lib/phony/countries/kyrgyzstan.rb +120 -0
  21. data/lib/phony/countries/latvia.rb +43 -0
  22. data/lib/phony/countries/libya.rb +116 -0
  23. data/lib/phony/countries/malaysia.rb +31 -7
  24. data/lib/phony/countries/moldova.rb +53 -0
  25. data/lib/phony/countries/montenegro.rb +30 -0
  26. data/lib/phony/countries/myanmar.rb +55 -0
  27. data/lib/phony/countries/namibia.rb +37 -0
  28. data/lib/phony/countries/nepal.rb +73 -0
  29. data/lib/phony/countries/netherlands.rb +17 -5
  30. data/lib/phony/countries/pakistan.rb +121 -0
  31. data/lib/phony/countries/paraguay.rb +147 -0
  32. data/lib/phony/countries/{russia_kazakhstan_abhasia_south_osetia.rb → russia_kazakhstan_abkhasia_south_ossetia.rb} +35 -24
  33. data/lib/phony/countries/saudi_arabia.rb +40 -0
  34. data/lib/phony/countries/serbia.rb +47 -0
  35. data/lib/phony/countries/somalia.rb +26 -0
  36. data/lib/phony/countries/south_korea.rb +19 -10
  37. data/lib/phony/countries/sweden.rb +58 -38
  38. data/lib/phony/countries/taiwan.rb +28 -0
  39. data/lib/phony/countries/tajikistan.rb +79 -0
  40. data/lib/phony/countries/turkmenistan.rb +76 -0
  41. data/lib/phony/countries/ukraine.rb +630 -0
  42. data/lib/phony/countries/united_kingdom.rb +639 -44
  43. data/lib/phony/countries/uruguay.rb +53 -0
  44. data/lib/phony/countries/vietnam.rb +133 -0
  45. data/lib/phony/countries/zimbabwe.rb +39 -0
  46. data/lib/phony/countries.rb +901 -301
  47. data/lib/phony/country.rb +177 -20
  48. data/lib/phony/country_codes.rb +119 -101
  49. data/lib/phony/dsl.rb +113 -68
  50. data/lib/phony/local_splitters/fixed.rb +25 -1
  51. data/lib/phony/local_splitters/regex.rb +16 -2
  52. data/lib/phony/national_code.rb +7 -7
  53. data/lib/phony/national_splitters/default.rb +35 -3
  54. data/lib/phony/national_splitters/dsl.rb +12 -7
  55. data/lib/phony/national_splitters/fixed.rb +7 -1
  56. data/lib/phony/national_splitters/none.rb +7 -3
  57. data/lib/phony/national_splitters/regex.rb +6 -0
  58. data/lib/phony/national_splitters/variable.rb +13 -9
  59. data/lib/phony/trunk_code.rb +57 -0
  60. data/lib/phony/vanity.rb +3 -3
  61. data/lib/phony.rb +239 -55
  62. data/spec/functional/config_spec.rb +44 -0
  63. data/spec/functional/plausibility_spec.rb +656 -0
  64. data/spec/lib/phony/countries_spec.rb +1207 -119
  65. data/spec/lib/phony/country_codes_spec.rb +99 -81
  66. data/spec/lib/phony/country_spec.rb +54 -14
  67. data/spec/lib/phony/dsl_spec.rb +2 -2
  68. data/spec/lib/phony/local_splitters/fixed_spec.rb +4 -4
  69. data/spec/lib/phony/local_splitters/regex_spec.rb +50 -2
  70. data/spec/lib/phony/national_code_spec.rb +34 -34
  71. data/spec/lib/phony/national_splitters/default_spec.rb +34 -0
  72. data/spec/lib/phony/national_splitters/fixed_spec.rb +12 -6
  73. data/spec/lib/phony/national_splitters/none_spec.rb +13 -3
  74. data/spec/lib/phony/national_splitters/regex_spec.rb +1 -1
  75. data/spec/lib/phony/national_splitters/variable_spec.rb +11 -5
  76. data/spec/lib/phony/trunk_code_spec.rb +85 -0
  77. data/spec/lib/phony/vanity_spec.rb +15 -19
  78. data/spec/lib/phony_spec.rb +59 -277
  79. metadata +67 -34
  80. data/lib/phony/validator.rb +0 -26
  81. data/lib/phony/validators.rb +0 -88
  82. data/spec/lib/phony/validations_spec.rb +0 -109
metadata CHANGED
@@ -1,38 +1,70 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phony
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.0
5
- prerelease:
4
+ version: 2.19.14
6
5
  platform: ruby
7
6
  authors:
8
7
  - Florian Hanke
9
- autorequire:
8
+ autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-02-21 00:00:00.000000000 Z
11
+ date: 2022-07-13 00:00:00.000000000 Z
13
12
  dependencies: []
14
- description: ! 'Fast international phone number (E164 standard) normalizing, splitting
13
+ description: 'Fast international phone number (E164 standard) normalizing, splitting
15
14
  and formatting. Lots of formatting options: International (+.., 00..), national
16
- (0..), and local).'
15
+ (0..), and local.'
17
16
  email: florian.hanke+phony@gmail.com
18
17
  executables: []
19
18
  extensions: []
20
19
  extra_rdoc_files:
21
20
  - README.textile
22
21
  files:
22
+ - README.textile
23
+ - lib/phony.rb
24
+ - lib/phony/config.rb
25
+ - lib/phony/countries.rb
26
+ - lib/phony/countries/argentina.rb
23
27
  - lib/phony/countries/austria.rb
28
+ - lib/phony/countries/bangladesh.rb
29
+ - lib/phony/countries/belarus.rb
24
30
  - lib/phony/countries/brazil.rb
31
+ - lib/phony/countries/cambodia.rb
25
32
  - lib/phony/countries/china.rb
33
+ - lib/phony/countries/croatia.rb
34
+ - lib/phony/countries/georgia.rb
26
35
  - lib/phony/countries/germany.rb
36
+ - lib/phony/countries/guinea.rb
37
+ - lib/phony/countries/india.rb
38
+ - lib/phony/countries/indonesia.rb
27
39
  - lib/phony/countries/ireland.rb
28
40
  - lib/phony/countries/italy.rb
41
+ - lib/phony/countries/japan.rb
42
+ - lib/phony/countries/kyrgyzstan.rb
43
+ - lib/phony/countries/latvia.rb
44
+ - lib/phony/countries/libya.rb
29
45
  - lib/phony/countries/malaysia.rb
46
+ - lib/phony/countries/moldova.rb
47
+ - lib/phony/countries/montenegro.rb
48
+ - lib/phony/countries/myanmar.rb
49
+ - lib/phony/countries/namibia.rb
50
+ - lib/phony/countries/nepal.rb
30
51
  - lib/phony/countries/netherlands.rb
31
- - lib/phony/countries/russia_kazakhstan_abhasia_south_osetia.rb
52
+ - lib/phony/countries/pakistan.rb
53
+ - lib/phony/countries/paraguay.rb
54
+ - lib/phony/countries/russia_kazakhstan_abkhasia_south_ossetia.rb
55
+ - lib/phony/countries/saudi_arabia.rb
56
+ - lib/phony/countries/serbia.rb
57
+ - lib/phony/countries/somalia.rb
32
58
  - lib/phony/countries/south_korea.rb
33
59
  - lib/phony/countries/sweden.rb
60
+ - lib/phony/countries/taiwan.rb
61
+ - lib/phony/countries/tajikistan.rb
62
+ - lib/phony/countries/turkmenistan.rb
63
+ - lib/phony/countries/ukraine.rb
34
64
  - lib/phony/countries/united_kingdom.rb
35
- - lib/phony/countries.rb
65
+ - lib/phony/countries/uruguay.rb
66
+ - lib/phony/countries/vietnam.rb
67
+ - lib/phony/countries/zimbabwe.rb
36
68
  - lib/phony/country.rb
37
69
  - lib/phony/country_codes.rb
38
70
  - lib/phony/dsl.rb
@@ -45,11 +77,10 @@ files:
45
77
  - lib/phony/national_splitters/none.rb
46
78
  - lib/phony/national_splitters/regex.rb
47
79
  - lib/phony/national_splitters/variable.rb
48
- - lib/phony/validator.rb
49
- - lib/phony/validators.rb
80
+ - lib/phony/trunk_code.rb
50
81
  - lib/phony/vanity.rb
51
- - lib/phony.rb
52
- - README.textile
82
+ - spec/functional/config_spec.rb
83
+ - spec/functional/plausibility_spec.rb
53
84
  - spec/lib/phony/countries_spec.rb
54
85
  - spec/lib/phony/country_codes_spec.rb
55
86
  - spec/lib/phony/country_spec.rb
@@ -57,51 +88,53 @@ files:
57
88
  - spec/lib/phony/local_splitters/fixed_spec.rb
58
89
  - spec/lib/phony/local_splitters/regex_spec.rb
59
90
  - spec/lib/phony/national_code_spec.rb
91
+ - spec/lib/phony/national_splitters/default_spec.rb
60
92
  - spec/lib/phony/national_splitters/fixed_spec.rb
61
93
  - spec/lib/phony/national_splitters/none_spec.rb
62
94
  - spec/lib/phony/national_splitters/regex_spec.rb
63
95
  - spec/lib/phony/national_splitters/variable_spec.rb
64
- - spec/lib/phony/validations_spec.rb
96
+ - spec/lib/phony/trunk_code_spec.rb
65
97
  - spec/lib/phony/vanity_spec.rb
66
98
  - spec/lib/phony_spec.rb
67
- homepage: http://github.com/floere/phony
68
- licenses: []
69
- post_install_message:
99
+ homepage: https://github.com/floere/phony
100
+ licenses:
101
+ - MIT
102
+ metadata: {}
103
+ post_install_message:
70
104
  rdoc_options: []
71
105
  require_paths:
72
106
  - lib
73
107
  required_ruby_version: !ruby/object:Gem::Requirement
74
- none: false
75
108
  requirements:
76
- - - ! '>='
109
+ - - ">="
77
110
  - !ruby/object:Gem::Version
78
111
  version: '0'
79
112
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
113
  requirements:
82
- - - ! '>='
114
+ - - ">="
83
115
  - !ruby/object:Gem::Version
84
116
  version: '0'
85
117
  requirements: []
86
- rubyforge_project:
87
- rubygems_version: 1.8.23
88
- signing_key:
89
- specification_version: 3
118
+ rubygems_version: 3.0.3
119
+ signing_key:
120
+ specification_version: 4
90
121
  summary: Fast international phone number (E164 standard) normalizing, splitting and
91
122
  formatting.
92
123
  test_files:
93
- - spec/lib/phony/countries_spec.rb
94
- - spec/lib/phony/country_codes_spec.rb
124
+ - spec/lib/phony_spec.rb
125
+ - spec/lib/phony/trunk_code_spec.rb
95
126
  - spec/lib/phony/country_spec.rb
96
- - spec/lib/phony/dsl_spec.rb
97
- - spec/lib/phony/local_splitters/fixed_spec.rb
98
- - spec/lib/phony/local_splitters/regex_spec.rb
99
127
  - spec/lib/phony/national_code_spec.rb
100
- - spec/lib/phony/national_splitters/fixed_spec.rb
128
+ - spec/lib/phony/countries_spec.rb
129
+ - spec/lib/phony/dsl_spec.rb
130
+ - spec/lib/phony/national_splitters/variable_spec.rb
101
131
  - spec/lib/phony/national_splitters/none_spec.rb
102
132
  - spec/lib/phony/national_splitters/regex_spec.rb
103
- - spec/lib/phony/national_splitters/variable_spec.rb
104
- - spec/lib/phony/validations_spec.rb
133
+ - spec/lib/phony/national_splitters/fixed_spec.rb
134
+ - spec/lib/phony/national_splitters/default_spec.rb
135
+ - spec/lib/phony/country_codes_spec.rb
136
+ - spec/lib/phony/local_splitters/regex_spec.rb
137
+ - spec/lib/phony/local_splitters/fixed_spec.rb
105
138
  - spec/lib/phony/vanity_spec.rb
106
- - spec/lib/phony_spec.rb
107
- has_rdoc: false
139
+ - spec/functional/config_spec.rb
140
+ - spec/functional/plausibility_spec.rb
@@ -1,26 +0,0 @@
1
- module Phony
2
-
3
- class Validator
4
-
5
- attr_reader :ndc_checks
6
-
7
- def initialize
8
- @ndc_checks = []
9
- end
10
-
11
- def plausible? ndc, rest
12
- ndc_checks && ndc_checks.each do |ndc_check|
13
- return false if ndc_check === ndc
14
- end
15
-
16
- true
17
- end
18
-
19
- def ndc_check ndc
20
- @ndc_checks << ndc
21
- self
22
- end
23
-
24
- end
25
-
26
- end
@@ -1,88 +0,0 @@
1
- # # Number: A possible phone number, E164 or not.
2
- # # Hints: Information that helps or constricts the plausibility check.
3
- # #
4
- # plausible? number, hints = {}
5
- #
6
-
7
- # plausible? number # Uses the definitions from the country definition to plausibility check.
8
- # plausible? number, cc: 1 # => Checks cc.
9
- # plausible? number, pattern: /[^5]/ # Uses def, checks against split.
10
- # plausible? number, country: 1, pattern: [3, 4, 3] # Uses given country – adds cc.
11
- #
12
-
13
- # Basic plausibility is:
14
- # * Max digits are 15.
15
- # * Min digits are 2 (?)
16
- #
17
-
18
- module Phony
19
-
20
- class Validators
21
-
22
- def initialize
23
- @validators = {}
24
- end
25
-
26
- def self.instance
27
- @instance ||= new
28
- end
29
-
30
- # Add a specific country validator.
31
- #
32
- def add cc, validator
33
- @validators[cc] = validator
34
- end
35
-
36
- # Is the given number plausible?
37
- #
38
- def plausible? number, hints = {}
39
- normalized = CountryCodes.instance.clean number
40
-
41
- # False if it fails the basic check.
42
- #
43
- return false unless (4..15) === normalized.size
44
-
45
- # Hint based checking.
46
- #
47
- cc, ndc, *rest = Phony.split normalized
48
-
49
- # Element based checking.
50
- #
51
- # Note: ndc == false means the country has none.
52
- #
53
- return false if ndc.nil?
54
- return false if ndc && ndc.empty?
55
-
56
- # A valid range for the rest is 0 or 3+ total digits.
57
- #
58
- return false if (1..2) === rest.reduce(0) { |total, string| total + string.size }
59
-
60
- # CC.
61
- #
62
- cc_needed = hints[:cc]
63
- return false if cc_needed && !(cc_needed === cc)
64
-
65
- # NDC.
66
- #
67
- ndc_needed = hints[:ndc]
68
- return false if ndc_needed && !(ndc_needed === ndc)
69
-
70
- # Country specific checks.
71
- #
72
- validator = validator_for cc
73
- validator.plausible? ndc, rest
74
- rescue StandardError
75
- return false
76
- end
77
-
78
- def validator_for cc
79
- @validators[cc] || default_validator
80
- end
81
-
82
- def default_validator
83
- @default_validator ||= Validator.new
84
- end
85
-
86
- end
87
-
88
- end
@@ -1,109 +0,0 @@
1
- # encoding: utf-8
2
- #
3
- require 'spec_helper'
4
-
5
- describe 'validations' do
6
-
7
- describe 'plausible?' do
8
-
9
- it 'does not change the given number' do
10
- number = "123-123-1234"
11
-
12
- Phony.plausible? number
13
-
14
- number.should == '123-123-1234'
15
- end
16
-
17
- it 'handles small numbers' do
18
- Phony.plausible?('353').should be_false
19
- end
20
-
21
- # TODO
22
- # it 'is correct' do
23
- # Phony.plausible?('+1911').should be_false
24
- # end
25
- it "correctly plausibilizes to#{}do countries" do
26
- Phony.plausible?('6327332350').should be_true
27
- end
28
- it 'is correct' do
29
- Phony.plausible?('45 44 11 22 33').should be_true
30
- end
31
- it 'is correct' do
32
- Phony.plausible?('+4231231212').should be_true
33
- end
34
- it 'is correct' do
35
- Phony.plausible?('010').should be_false
36
- end
37
- it 'is correct' do
38
- Phony.plausible?("+460000").should be_false
39
- end
40
- it 'is correct' do
41
- Phony.plausible?('0000000').should be_false
42
- end
43
- it 'is correct' do
44
- Phony.plausible?('hello').should be_false
45
- end
46
-
47
- it "is correct" do
48
- Phony.plausible?('+41 44 111 22 33').should be_true
49
- end
50
- it "is correct for explicit checks" do
51
- Phony.plausible?('+41 44 111 22 33', cc: '41').should be_true
52
- end
53
- it "is correct for explicit checks" do
54
- Phony.plausible?('+41 44 111 22 33', ndc: '44').should be_true
55
- end
56
- it "is correct for explicit checks" do
57
- Phony.plausible?('+41 44 111 22 33', cc: '1').should be_false
58
- end
59
- it "is correct for explicit checks" do
60
- Phony.plausible?('+41 44 111 22 33', ndc: '43').should be_false
61
- end
62
- it "is correct for explicit checks" do
63
- Phony.plausible?('+41 44 111 22 33', cc: '41', ndc: '44').should be_true
64
- end
65
- it "works with regexps" do
66
- Phony.plausible?('+41 44 111 22 33', cc: /4(0|2)/, ndc: /4(4|5)/).should be_false
67
- end
68
- it "works with regexps" do
69
- Phony.plausible?('+41 44 111 22 33', cc: /4(0|1)/, ndc: /4(4|5)/).should be_true
70
- end
71
-
72
- context 'specific countries' do
73
-
74
- # TODO
75
- #
76
- # it "is correct for Swiss numbers" do
77
- # Phony.plausible?('+41 44 111 22 33').should be_true
78
- # end
79
-
80
- it "is correct for US numbers" do
81
- # Sorry, still need E164 conform numbers.
82
- #
83
- Phony.plausible?('4346667777', cc: '1').should be_false
84
-
85
- # Automatic country checking.
86
- #
87
- Phony.plausible?('1-4346667777').should be_true
88
- Phony.plausible?('1-800-692-7753').should be_true
89
- Phony.plausible?('1-911').should be_false
90
- Phony.plausible?('1-911-123-1234').should be_false
91
-
92
- # With string constraints.
93
- #
94
- Phony.plausible?('14346667777', cc: '1').should be_true
95
- Phony.plausible?('14346667777', ndc: '434').should be_true
96
- Phony.plausible?('14346667777', cc: '1', ndc: '434').should be_true
97
-
98
- # With regexp constraints.
99
- #
100
- Phony.plausible?('14346667777', cc: /[123]/).should be_true
101
- Phony.plausible?('14346667777', ndc: /434|435/).should be_true
102
- Phony.plausible?('14346667777', cc: /[123]/, ndc: /434|435/).should be_true
103
- end
104
-
105
- end
106
-
107
- end
108
-
109
- end