phony 1.0.1 → 1.1.0
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/README.textile +14 -2
- data/lib/phony.rb +58 -463
- data/lib/phony/countries/all_other.rb +417 -0
- data/lib/phony/countries/austria.rb +69 -0
- data/lib/phony/countries/egypt.rb +40 -0
- data/lib/phony/countries/germany.rb +156 -0
- data/lib/phony/countries/greece.rb +30 -0
- data/lib/phony/countries/hungary.rb +23 -0
- data/lib/phony/countries/italy.rb +105 -0
- data/lib/phony/country.rb +102 -0
- data/lib/phony/country_codes.rb +102 -0
- data/lib/phony/local_splitter.rb +46 -0
- data/lib/phony/national_code.rb +27 -0
- data/lib/phony/national_splitters/fixed.rb +36 -0
- data/lib/phony/national_splitters/variable.rb +64 -0
- data/lib/phony/vanity.rb +35 -0
- data/spec/lib/phony/countries/austria_spec.rb +24 -0
- data/spec/lib/phony/countries/egypt_spec.rb +18 -0
- data/spec/lib/phony/countries/germany_spec.rb +24 -0
- data/spec/lib/phony/countries/greece_spec.rb +18 -0
- data/spec/lib/phony/countries/hungary_spec.rb +18 -0
- data/spec/lib/phony/countries/switzerland_spec.rb +18 -0
- data/spec/lib/phony/country_codes_spec.rb +110 -0
- data/spec/lib/phony/country_spec.rb +91 -0
- data/spec/lib/phony/local_splitter_spec.rb +48 -0
- data/spec/lib/phony/national_code_spec.rb +36 -0
- data/spec/lib/phony/national_splitters/fixed_spec.rb +43 -0
- data/spec/lib/phony/national_splitters/variable_spec.rb +35 -0
- data/spec/lib/phony/vanity_spec.rb +34 -0
- data/spec/lib/phony_spec.rb +117 -238
- metadata +45 -21
- data/lib/ndc/austria.rb +0 -69
- data/lib/ndc/fixed_size.rb +0 -113
- data/lib/ndc/germany.rb +0 -157
- data/lib/ndc/prefix.rb +0 -67
- data/lib/ndc/splitter.rb +0 -81
- data/spec/lib/ndc/austria_spec.rb +0 -40
- data/spec/lib/ndc/fixed_size_spec.rb +0 -65
- data/spec/lib/ndc/germany_spec.rb +0 -40
- data/spec/lib/ndc/prefix_spec.rb +0 -25
- data/spec/lib/ndc/splitter_spec.rb +0 -59
metadata
CHANGED
@@ -4,22 +4,21 @@ version: !ruby/object:Gem::Version
|
|
4
4
|
prerelease: false
|
5
5
|
segments:
|
6
6
|
- 1
|
7
|
-
- 0
|
8
7
|
- 1
|
9
|
-
|
8
|
+
- 0
|
9
|
+
version: 1.1.0
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Florian Hanke
|
13
|
-
- Andreas Schacke
|
14
13
|
autorequire:
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2010-11-
|
17
|
+
date: 2010-11-26 00:00:00 +01:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
22
|
-
description:
|
21
|
+
description: "Fast international phone number (E164 standard) normalizing, splitting and formatting. Lots of formatting options: International (+.., 00..), national (0..), and local)."
|
23
22
|
email: florian.hanke+phony@gmail.com
|
24
23
|
executables: []
|
25
24
|
|
@@ -28,18 +27,35 @@ extensions: []
|
|
28
27
|
extra_rdoc_files:
|
29
28
|
- README.textile
|
30
29
|
files:
|
31
|
-
- lib/
|
32
|
-
- lib/
|
33
|
-
- lib/
|
34
|
-
- lib/
|
35
|
-
- lib/
|
30
|
+
- lib/phony/countries/all_other.rb
|
31
|
+
- lib/phony/countries/austria.rb
|
32
|
+
- lib/phony/countries/egypt.rb
|
33
|
+
- lib/phony/countries/germany.rb
|
34
|
+
- lib/phony/countries/greece.rb
|
35
|
+
- lib/phony/countries/hungary.rb
|
36
|
+
- lib/phony/countries/italy.rb
|
37
|
+
- lib/phony/country.rb
|
38
|
+
- lib/phony/country_codes.rb
|
39
|
+
- lib/phony/local_splitter.rb
|
40
|
+
- lib/phony/national_code.rb
|
41
|
+
- lib/phony/national_splitters/fixed.rb
|
42
|
+
- lib/phony/national_splitters/variable.rb
|
43
|
+
- lib/phony/vanity.rb
|
36
44
|
- lib/phony.rb
|
37
45
|
- README.textile
|
38
|
-
- spec/lib/
|
39
|
-
- spec/lib/
|
40
|
-
- spec/lib/
|
41
|
-
- spec/lib/
|
42
|
-
- spec/lib/
|
46
|
+
- spec/lib/phony/countries/austria_spec.rb
|
47
|
+
- spec/lib/phony/countries/egypt_spec.rb
|
48
|
+
- spec/lib/phony/countries/germany_spec.rb
|
49
|
+
- spec/lib/phony/countries/greece_spec.rb
|
50
|
+
- spec/lib/phony/countries/hungary_spec.rb
|
51
|
+
- spec/lib/phony/countries/switzerland_spec.rb
|
52
|
+
- spec/lib/phony/country_codes_spec.rb
|
53
|
+
- spec/lib/phony/country_spec.rb
|
54
|
+
- spec/lib/phony/local_splitter_spec.rb
|
55
|
+
- spec/lib/phony/national_code_spec.rb
|
56
|
+
- spec/lib/phony/national_splitters/fixed_spec.rb
|
57
|
+
- spec/lib/phony/national_splitters/variable_spec.rb
|
58
|
+
- spec/lib/phony/vanity_spec.rb
|
43
59
|
- spec/lib/phony_spec.rb
|
44
60
|
has_rdoc: false
|
45
61
|
homepage: http://github.com/floere/phony
|
@@ -72,11 +88,19 @@ rubyforge_project:
|
|
72
88
|
rubygems_version: 1.3.7
|
73
89
|
signing_key:
|
74
90
|
specification_version: 3
|
75
|
-
summary: E164
|
91
|
+
summary: Fast international phone number (E164 standard) normalizing, splitting and formatting.
|
76
92
|
test_files:
|
77
|
-
- spec/lib/
|
78
|
-
- spec/lib/
|
79
|
-
- spec/lib/
|
80
|
-
- spec/lib/
|
81
|
-
- spec/lib/
|
93
|
+
- spec/lib/phony/countries/austria_spec.rb
|
94
|
+
- spec/lib/phony/countries/egypt_spec.rb
|
95
|
+
- spec/lib/phony/countries/germany_spec.rb
|
96
|
+
- spec/lib/phony/countries/greece_spec.rb
|
97
|
+
- spec/lib/phony/countries/hungary_spec.rb
|
98
|
+
- spec/lib/phony/countries/switzerland_spec.rb
|
99
|
+
- spec/lib/phony/country_codes_spec.rb
|
100
|
+
- spec/lib/phony/country_spec.rb
|
101
|
+
- spec/lib/phony/local_splitter_spec.rb
|
102
|
+
- spec/lib/phony/national_code_spec.rb
|
103
|
+
- spec/lib/phony/national_splitters/fixed_spec.rb
|
104
|
+
- spec/lib/phony/national_splitters/variable_spec.rb
|
105
|
+
- spec/lib/phony/vanity_spec.rb
|
82
106
|
- spec/lib/phony_spec.rb
|
data/lib/ndc/austria.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
# Splits a national number into a fixed size NDC and rest.
|
2
|
-
#
|
3
|
-
module Phony
|
4
|
-
module NDC
|
5
|
-
class Austria < Prefix
|
6
|
-
|
7
|
-
length 1..4
|
8
|
-
local 10
|
9
|
-
|
10
|
-
ndcs '1',# Wient
|
11
|
-
'57', # -
|
12
|
-
'59', # -
|
13
|
-
'67', # Mobile Services
|
14
|
-
'68', # Mobile Services
|
15
|
-
'89', # Routing Number
|
16
|
-
'316', # Graz
|
17
|
-
'501', # -
|
18
|
-
'502', # -
|
19
|
-
'503', # -
|
20
|
-
'504', # -
|
21
|
-
'505', # -
|
22
|
-
'506', # -
|
23
|
-
'507', # -
|
24
|
-
'508', # -
|
25
|
-
'509', # -
|
26
|
-
'512', # Innsbruck
|
27
|
-
'517', # -
|
28
|
-
'644', # Mobile Services
|
29
|
-
'650', # Mobile Services
|
30
|
-
'651', # Mobile Services
|
31
|
-
'652', # Mobile Services
|
32
|
-
'653', # Mobile Services
|
33
|
-
'655', # Mobile Services
|
34
|
-
'657', # Mobile Services
|
35
|
-
'659', # Mobile Services
|
36
|
-
'660', # Mobile Services
|
37
|
-
'661', # Mobile Services
|
38
|
-
'662', # Salzburg
|
39
|
-
'663', # Mobile Services
|
40
|
-
'664', # Mobile Services
|
41
|
-
'665', # Mobile Services
|
42
|
-
'666', # Mobile Services
|
43
|
-
'667', # Mobile Services
|
44
|
-
'668', # Mobile Services
|
45
|
-
'669', # Mobile Services
|
46
|
-
'710', # Service Number
|
47
|
-
'711', # Service Number
|
48
|
-
'718', # Service Number
|
49
|
-
'720', #
|
50
|
-
'730', # Service Number
|
51
|
-
'732', # Linz
|
52
|
-
'740', # Service Number
|
53
|
-
'780', # Service Number
|
54
|
-
'800', # Service Number
|
55
|
-
'802', # Service Number
|
56
|
-
'804', # Service Number
|
57
|
-
'810', # Service Number
|
58
|
-
'820', # Service Number
|
59
|
-
'821', # Service Number
|
60
|
-
'828', # Service Number
|
61
|
-
'900', # Service Number
|
62
|
-
'901', # Service Number
|
63
|
-
'930', # Service Number
|
64
|
-
'931', # Service Number
|
65
|
-
'939' # Service Number
|
66
|
-
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
data/lib/ndc/fixed_size.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
# Splits a national number into a fixed size NDC and rest.
|
2
|
-
#
|
3
|
-
module Phony
|
4
|
-
module NDC
|
5
|
-
|
6
|
-
def self.fixed(national_code_length = 2, options = {})
|
7
|
-
klass = Class.new FixedSize
|
8
|
-
split_sizes, special_ndcs = klass.extract options
|
9
|
-
klass.special_ndc_strategy Phony::NDC::SpecialNdcStrategy.new(national_code_length, special_ndcs)
|
10
|
-
klass.fixed_ndc_strategy Phony::NDC::FixedNdcStrategy.new(national_code_length, split_sizes)
|
11
|
-
klass.format options[:format] || '%s%s%s%s%s'
|
12
|
-
klass.local split_sizes
|
13
|
-
klass
|
14
|
-
end
|
15
|
-
|
16
|
-
class FixedSize < Splitter
|
17
|
-
|
18
|
-
def self.extract options
|
19
|
-
[options[:local] || [3, 2, 2], options[:special_ndcs] || []]
|
20
|
-
end
|
21
|
-
|
22
|
-
# Sets the strategy object to handle special services numbers
|
23
|
-
def self.special_ndc_strategy strategy
|
24
|
-
@special_ndc_strategy = strategy
|
25
|
-
end
|
26
|
-
|
27
|
-
# Sets the strategy object to handle normal numbers (non special services)
|
28
|
-
def self.fixed_ndc_strategy strategy
|
29
|
-
@fixed_ndc_strategy = strategy
|
30
|
-
@ndc_strategy = @fixed_ndc_strategy
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns true if the number is a special services number
|
34
|
-
def self.special_ndc? number
|
35
|
-
@special_ndc_strategy.special_ndc? number
|
36
|
-
end
|
37
|
-
|
38
|
-
# Define a format for the country's national format.
|
39
|
-
#
|
40
|
-
# Default is NN followed by a space.
|
41
|
-
#
|
42
|
-
def self.ndc_format
|
43
|
-
@ndc_format || @ndc_format = @ndc_strategy.ndc_format
|
44
|
-
end
|
45
|
-
|
46
|
-
# A faster split method than the prefix splitter offers.
|
47
|
-
#
|
48
|
-
def self.split_ndc number
|
49
|
-
number = number.dup
|
50
|
-
if special_ndc? number
|
51
|
-
@ndc_strategy = @special_ndc_strategy
|
52
|
-
else
|
53
|
-
@ndc_strategy = @fixed_ndc_strategy
|
54
|
-
end
|
55
|
-
@ndc_strategy.split_ndc number
|
56
|
-
end
|
57
|
-
|
58
|
-
def self.split_local number
|
59
|
-
@ndc_strategy.split_local number
|
60
|
-
end
|
61
|
-
|
62
|
-
end
|
63
|
-
|
64
|
-
# Base class for all Strategies
|
65
|
-
class NdcStrategy
|
66
|
-
attr_reader :split_sizes
|
67
|
-
|
68
|
-
def initialize national_code_length, split_sizes
|
69
|
-
@national_code_length = national_code_length
|
70
|
-
@split_sizes = split_sizes
|
71
|
-
end
|
72
|
-
|
73
|
-
def split_local number
|
74
|
-
local = []
|
75
|
-
split_sizes.each do |size|
|
76
|
-
local << number.slice!(0..size-1)
|
77
|
-
break if number.empty?
|
78
|
-
end
|
79
|
-
local
|
80
|
-
end
|
81
|
-
|
82
|
-
def ndc_format
|
83
|
-
'%s' + (@national_code_length == 0 ? '' : '%s')
|
84
|
-
end
|
85
|
-
|
86
|
-
end
|
87
|
-
|
88
|
-
class SpecialNdcStrategy < NdcStrategy
|
89
|
-
def initialize national_code_length, special_ndcs
|
90
|
-
super national_code_length, [2, 2, 2]
|
91
|
-
@special_ndcs = special_ndcs.flatten
|
92
|
-
@special_ndc_regexp = Regexp.compile "^(#{@special_ndcs.join('|')})"
|
93
|
-
end
|
94
|
-
|
95
|
-
def special_ndc? number
|
96
|
-
@special_ndcs && !@special_ndcs.empty? && @match = @special_ndc_regexp.match(number)
|
97
|
-
end
|
98
|
-
|
99
|
-
def split_ndc number
|
100
|
-
[number.slice!(0..@match[0].length-1), number]
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
class FixedNdcStrategy < NdcStrategy
|
105
|
-
|
106
|
-
def split_ndc number
|
107
|
-
@national_code_length.zero? ? ['', number] : [number.slice!(0..@national_code_length-1), number]
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
data/lib/ndc/germany.rb
DELETED
@@ -1,157 +0,0 @@
|
|
1
|
-
# Splits a german national number into a fixed size NDC and rest.
|
2
|
-
#
|
3
|
-
# Note: We do ignore places with 5 numbers as NDC, like Groß Glienicke (33201)
|
4
|
-
#
|
5
|
-
module Phony
|
6
|
-
module NDC
|
7
|
-
class Germany < Prefix
|
8
|
-
|
9
|
-
length 2..4
|
10
|
-
local 3, 10
|
11
|
-
|
12
|
-
# prefix length => [ndcs]
|
13
|
-
ndcs '10', # Call-By-Call
|
14
|
-
'11', # formerly Value Added Services
|
15
|
-
'12', # Innovative Services
|
16
|
-
'13', # Voting and Lottery Numbers
|
17
|
-
'30', # Berlin
|
18
|
-
'32', # Non Geographical Numbers
|
19
|
-
'40', # Hamburg
|
20
|
-
'69', # Frankfurt am Main
|
21
|
-
'89', # München
|
22
|
-
'150', # Group3G/Quam
|
23
|
-
'151', # T-Mobile
|
24
|
-
'152', # Vodafone
|
25
|
-
'155', # E-Plus
|
26
|
-
'156', # Mobilcom
|
27
|
-
'157', # E-Plus
|
28
|
-
'159', # O2
|
29
|
-
'160', # T-Mobile
|
30
|
-
'161', # C-Netz
|
31
|
-
'162', # Vodafone
|
32
|
-
'163', # E-Plus
|
33
|
-
'164', # Cityruf
|
34
|
-
'165', # Quix
|
35
|
-
'166', # Telmi
|
36
|
-
'168', # Scall
|
37
|
-
'169', # Cityruf, Scall, Skyper (e*cityruf, e*message, e*skyper)
|
38
|
-
'170', # T-Mobile
|
39
|
-
'171', # T-Mobile
|
40
|
-
'172', # Vodafone
|
41
|
-
'173', # Vodafone
|
42
|
-
'174', # Vodafone
|
43
|
-
'175', # T-Mobile
|
44
|
-
'176', # O2 Germany
|
45
|
-
'177', # E-Plus
|
46
|
-
'178', # E-Plus
|
47
|
-
'179', # O2 Germany
|
48
|
-
'181', # IVPNs
|
49
|
-
'182', # Closed User Group
|
50
|
-
'183', # Closed User Group
|
51
|
-
'184', # Closed User Group
|
52
|
-
'185', # Closed User Group
|
53
|
-
'186', # Closed User Group
|
54
|
-
'187', # Closed User Group
|
55
|
-
'189', # Closed User Group
|
56
|
-
'190', # former Premium Rate Services
|
57
|
-
'191', # Online Services
|
58
|
-
'192', # Online Services
|
59
|
-
'193', # Online Services
|
60
|
-
'194', # Online Services
|
61
|
-
'199', # Network-Internal Traffic Control
|
62
|
-
'201', # Essen
|
63
|
-
'202', # Wuppertal
|
64
|
-
'203', # Duisburg
|
65
|
-
'208', # Mühlheim an der Ruhr
|
66
|
-
'209', # Gelsenkirchen
|
67
|
-
'211', # Düsseldorf
|
68
|
-
'212', # Solingen
|
69
|
-
'214', # Leverkusen
|
70
|
-
'221', # Köln
|
71
|
-
'228', # Bonn
|
72
|
-
'231', # Dortmund
|
73
|
-
'234', # Bochum
|
74
|
-
'241', # Aachen
|
75
|
-
'251', # Münster
|
76
|
-
'261', # Koblenz
|
77
|
-
'271', # Siegen
|
78
|
-
'281', # Wesel
|
79
|
-
'291', # Meschede
|
80
|
-
'310', # Test Number Long Distance
|
81
|
-
'311', # Test Number Local
|
82
|
-
'335', # Frankfurt (Oder)
|
83
|
-
'340', # Dessau
|
84
|
-
'341', # Leipzig
|
85
|
-
'345', # Halle (Saale)
|
86
|
-
'351', # Dresden
|
87
|
-
'355', # Cottbus
|
88
|
-
'361', # Erfurt
|
89
|
-
'365', # Gera
|
90
|
-
'371', # Chemnitz
|
91
|
-
'375', # Zwickau
|
92
|
-
'381', # Rostock
|
93
|
-
'385', # Schwerin
|
94
|
-
'391', # Magdeburg
|
95
|
-
'395', # Neubrandenburg
|
96
|
-
'421', # Bremen
|
97
|
-
'431', # Kiel
|
98
|
-
'441', # Oldenburg
|
99
|
-
'461', # Flensburg
|
100
|
-
'471', # Bremerhaven
|
101
|
-
'481', # Heide
|
102
|
-
'491', # Leer
|
103
|
-
'511', # Hannover
|
104
|
-
'521', # Bielefeld
|
105
|
-
'531', # Braunschweig
|
106
|
-
'541', # Osnabrück
|
107
|
-
'551', # Göttingen
|
108
|
-
'561', # Kassel
|
109
|
-
'571', # Minden
|
110
|
-
'581', # Uelzen
|
111
|
-
'591', # Lingen (Ems)
|
112
|
-
'611', # Wiesbaden
|
113
|
-
'621', # Mannheim / Ludwigshafen
|
114
|
-
'631', # Kaiserslautern
|
115
|
-
'641', # Gießen
|
116
|
-
'651', # Trier
|
117
|
-
'661', # Fulda
|
118
|
-
'671', # Bad Kreuznach
|
119
|
-
'681', # Saarbrücken
|
120
|
-
'700', # Personal Numbers
|
121
|
-
'701', # Personal Numbers, reserved
|
122
|
-
'711', # Stuttgart
|
123
|
-
'721', # Karlsruhe
|
124
|
-
'731', # Ulm
|
125
|
-
'741', # Rottweil
|
126
|
-
'751', # Ravensburg
|
127
|
-
'761', # Freiburg im Breisgau
|
128
|
-
'771', # Donaueschingen
|
129
|
-
'781', # Offenburg
|
130
|
-
'791', # Schwäbisch Hall
|
131
|
-
'800', # Toll-Free Numbers
|
132
|
-
'801', # Toll-Free Numbers, reserved
|
133
|
-
'811', # Hallbergmoos
|
134
|
-
'821', # Augsburg
|
135
|
-
'831', # Kempten
|
136
|
-
'841', # Ingolstadt
|
137
|
-
'851', # Passau
|
138
|
-
'861', # Traunstein
|
139
|
-
'871', # Landshut
|
140
|
-
'881', # Weilheim in Oberbayern
|
141
|
-
'900', # Premium Rate Numbers
|
142
|
-
'901', # Premium Rate Numbers, reserved
|
143
|
-
'902', # Replacement for 0137/0138
|
144
|
-
'906', # Donauwörth
|
145
|
-
'911', # Nürnberg
|
146
|
-
'921', # Bayreuth
|
147
|
-
'931', # Würzburg
|
148
|
-
'941', # Regensburg
|
149
|
-
'951', # Bamberg
|
150
|
-
'961', # Weiden
|
151
|
-
'971', # Bad Kissingen
|
152
|
-
'981', # Ansbach
|
153
|
-
'991' # Deggendorf
|
154
|
-
|
155
|
-
end
|
156
|
-
end
|
157
|
-
end
|
data/lib/ndc/prefix.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
# Splits a national number using a prefix code.
|
2
|
-
#
|
3
|
-
# DSL:
|
4
|
-
# length: the length range of the dcs. For austria it is 1..4.
|
5
|
-
# format: the format of the dcs and rest. For austria it is '%s %s', default is '%s %s %s %s'.
|
6
|
-
# ndcs: an array of the prefix codes. For germany it starts with ['10', '11', '12', '13', '30'…
|
7
|
-
#
|
8
|
-
module Phony
|
9
|
-
module NDC
|
10
|
-
class Prefix < Splitter
|
11
|
-
|
12
|
-
# Splits the number into ndc and rest.
|
13
|
-
#
|
14
|
-
def self.split_ndc(number)
|
15
|
-
number = number.dup
|
16
|
-
presumed_code = ''
|
17
|
-
presumed_code << number.slice!(0..@min_ndc_length-2) if @min_ndc_length && @min_ndc_length > 1
|
18
|
-
(@min_ndc_length || 1).upto(@max_ndc_length) do |i|
|
19
|
-
presumed_code << number.slice!(0..0)
|
20
|
-
sized_ndcs = @ndcs[i]
|
21
|
-
break unless sized_ndcs && !sized_ndcs.include?(presumed_code)
|
22
|
-
end
|
23
|
-
return [presumed_code, number]
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
# Define the length range for the country's ndcs.
|
29
|
-
#
|
30
|
-
def self.length(range)
|
31
|
-
@min_ndc_length, @max_ndc_length = range.min, range.max
|
32
|
-
end
|
33
|
-
|
34
|
-
# Define the list of NDCs.
|
35
|
-
#
|
36
|
-
# Note: For optimization, if the country has a max ndc length of 4,
|
37
|
-
# only enter ndcs up to the length of 3 letters.
|
38
|
-
# If the algorithm fails to match an ndc, it will assume it is a 4 digit ndc.
|
39
|
-
#
|
40
|
-
# e.g. We have NDCs '1', '22', '333', and '4444'.
|
41
|
-
# Only set
|
42
|
-
# ndcs '1', '22', '333'
|
43
|
-
# and
|
44
|
-
# length 1..4
|
45
|
-
# '4444' will be "recognized" because the algorithm does not find a shorter ndc (assuming it
|
46
|
-
# is a correct prefix code) and stop at the max ndc length of 4, given by the length method.
|
47
|
-
#
|
48
|
-
def self.ndcs(*ndcs_ary)
|
49
|
-
@ndcs = optimize(ndcs_ary)
|
50
|
-
end
|
51
|
-
|
52
|
-
private
|
53
|
-
|
54
|
-
# Optimizes and restructures the given ndcs array.
|
55
|
-
#
|
56
|
-
def self.optimize(ndcs_ary)
|
57
|
-
ndcs = {}
|
58
|
-
ndcs_ary.each do |ndc|
|
59
|
-
ndcs[ndc.length] ||= []
|
60
|
-
ndcs[ndc.length] << ndc
|
61
|
-
end
|
62
|
-
ndcs
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|