phony 2.10.1 → 2.10.2
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/phony/countries/cambodia.rb +1 -0
- data/lib/phony/countries/italy.rb +12 -2
- data/lib/phony/dsl.rb +15 -7
- data/spec/functional/plausibility_spec.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb033161f929557a2dbf12d42456b2142d6137bb
|
4
|
+
data.tar.gz: 552cb66297f8145a4cf2a448a3babdd6e52ea156
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6e75ce246cc9b4f697682f54354467d62db2523e2b0465f27ffe32fd61380d7129ee923f4ca24790e777b6ca3f3819c47894c38a1e05bbf0c89521fb73ada50
|
7
|
+
data.tar.gz: fd809a13783a6fdb671945d458ba2c20cbd74d2244be497823cb26fc73e5fefd1f6f693aa92ceef276fedb99548c3f2d23ed078da210e6072f327a906da9cdfa
|
@@ -114,6 +114,16 @@ Phony.define do
|
|
114
114
|
one_of(*service) >> split(3,3) |
|
115
115
|
one_of(*mobile) >> split(3,4,-1..1) |
|
116
116
|
one_of(*ndcs_2digit) >> split(4,4) |
|
117
|
-
one_of(*ndcs_3digit) >>
|
118
|
-
|
117
|
+
one_of(*ndcs_3digit) >> matched_split(
|
118
|
+
/^1\d{6}$/ => [7],
|
119
|
+
/^1\d{7}$/ => [8],
|
120
|
+
/^[^1]\d{5}$/ => [6],
|
121
|
+
/^[^1]\d{6}$/ => [7]
|
122
|
+
) |
|
123
|
+
one_of(*ndcs_4digit) >> matched_split(
|
124
|
+
/^1\d{5}$/ => [6],
|
125
|
+
/^1\d{6}$/ => [7],
|
126
|
+
/^[^1]\d{4}$/ => [5],
|
127
|
+
/^[^1]\d{5}$/ => [3,3]
|
128
|
+
)
|
119
129
|
end
|
data/lib/phony/dsl.rb
CHANGED
@@ -66,7 +66,12 @@ module Phony
|
|
66
66
|
none >> split(10)
|
67
67
|
end
|
68
68
|
|
69
|
+
# This country uses a trunk code.
|
69
70
|
#
|
71
|
+
# Examples:
|
72
|
+
# * Hungary uses 06.
|
73
|
+
# * North America uses 1.
|
74
|
+
# * Most countries which use a trunk code use 0.
|
70
75
|
#
|
71
76
|
def trunk code, options = {}
|
72
77
|
TrunkCode.new code, options
|
@@ -84,9 +89,9 @@ module Phony
|
|
84
89
|
# * options: Set :zero to false to not add a zero on format :national.
|
85
90
|
#
|
86
91
|
# Example:
|
87
|
-
#
|
92
|
+
# # France, uses a fixed NDC of size 1.
|
93
|
+
# country '33', fixed(1) >> split(2,2,2,2)
|
88
94
|
#
|
89
|
-
|
90
95
|
def fixed length, options = {}
|
91
96
|
options[:zero] = true if options[:zero].nil?
|
92
97
|
NationalSplitters::Fixed.instance_for length, options
|
@@ -112,7 +117,9 @@ module Phony
|
|
112
117
|
# * Can contain :max_length => number to denote a maximum NDC length.
|
113
118
|
#
|
114
119
|
# Example:
|
115
|
-
# country '51',
|
120
|
+
# country '51',
|
121
|
+
# # If it's either 103 or 105, then split ...
|
122
|
+
# one_of('103', '105') >> split(3,3)
|
116
123
|
#
|
117
124
|
def one_of *ndcs
|
118
125
|
options = Hash === ndcs.last ? ndcs.pop : {}
|
@@ -149,6 +156,8 @@ module Phony
|
|
149
156
|
|
150
157
|
# Splits the number into groups of given sizes.
|
151
158
|
#
|
159
|
+
# Also takes ranges.
|
160
|
+
#
|
152
161
|
# Example:
|
153
162
|
# match(/^(0\d{2})\d+$/) >> split(2,2,2,2) # If it matches, split in 4 groups of size 2.
|
154
163
|
#
|
@@ -160,20 +169,19 @@ module Phony
|
|
160
169
|
# Matches on the rest of the number and splits according
|
161
170
|
# to the given value for the regexp key.
|
162
171
|
#
|
172
|
+
# Also takes ranges.
|
173
|
+
#
|
163
174
|
# Options:
|
164
175
|
# * fallback A fallback amount of group sizes in case it doesn't match.
|
165
176
|
#
|
166
177
|
# Example:
|
178
|
+
# # Norway
|
167
179
|
# country '47',
|
168
180
|
# none >> matched_split(/^[1].*$/ => [3],
|
169
181
|
# /^[489].*$/ => [3,2,3],
|
170
182
|
# :fallback => [2,2,2,2])
|
171
183
|
#
|
172
184
|
def matched_split options = {}
|
173
|
-
# # TODO: Refactor: it's a workaround. It creates high coupling with Phony::LocalSplitters::Regex.
|
174
|
-
# options.each do |_, format|
|
175
|
-
# format << format.pop + 10
|
176
|
-
# end
|
177
185
|
Phony::LocalSplitters::Regex.instance_for options
|
178
186
|
end
|
179
187
|
|
@@ -267,6 +267,8 @@ describe 'plausibility' do
|
|
267
267
|
Phony.plausible?("+85588234567").should be_false # Metfone (too short)
|
268
268
|
Phony.plausible?("+855972345678").should be_true # Metfone (7 digit id)
|
269
269
|
Phony.plausible?("+85597234567").should be_false # Metfone (too short)
|
270
|
+
Phony.plausible?("+855714822684").should be_true # Metfone (7 digit id)
|
271
|
+
Phony.plausible?("+85571482268").should be_false # Metfone (too short)
|
270
272
|
|
271
273
|
Phony.plausible?("+85513234567").should be_true # qb (6 digit id)
|
272
274
|
Phony.plausible?("+855132345678").should be_false # qb (too long)
|
@@ -410,6 +412,9 @@ describe 'plausibility' do
|
|
410
412
|
|
411
413
|
Phony.plausible?('+39 0471 123 456').should be_true
|
412
414
|
|
415
|
+
# Issue #221
|
416
|
+
Phony.plausible?('+39 081 1925 2698').should be_true
|
417
|
+
|
413
418
|
# Mobile
|
414
419
|
Phony.plausible?('+39 335 123').should be_false
|
415
420
|
Phony.plausible?('+39 335 123 45').should be_false
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phony
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.10.
|
4
|
+
version: 2.10.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Florian Hanke
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Fast international phone number (E164 standard) normalizing, splitting
|
14
14
|
and formatting. Lots of formatting options: International (+.., 00..), national
|