phonelib 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{README.rdoc → README.md} +116 -75
- data/data/extended_data.dat +0 -0
- data/data/libphonenumber/FALSEHOODS.md +16 -0
- data/data/libphonenumber/FAQ.md +8 -0
- data/data/libphonenumber/README.md +1 -1
- data/data/libphonenumber/cpp/src/phonenumbers/alternate_format.cc +108 -100
- data/data/libphonenumber/cpp/src/phonenumbers/lite_metadata.cc +10070 -10016
- data/data/libphonenumber/cpp/src/phonenumbers/metadata.cc +10938 -10884
- data/data/libphonenumber/cpp/src/phonenumbers/short_metadata.cc +2481 -2455
- data/data/libphonenumber/java/carrier/pom.xml +26 -4
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/255_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/374_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/374_ru +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/421_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/66_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/91_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/93_fa +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/973_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/98_fa +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/992_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/994_en +0 -0
- data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/config +0 -0
- data/data/libphonenumber/java/demo/pom.xml +6 -6
- data/data/libphonenumber/java/geocoder/pom.xml +26 -4
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1747_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/1934_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/371_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/44_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/504_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_bg +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_ca +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_el +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_es +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_fi +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_hi +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_hu +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_iw +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_ja +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/82_tr +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/91_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/93_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/93_fa +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/98_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/98_fa +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/992_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/994_en +0 -0
- data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/config +0 -0
- data/data/libphonenumber/java/internal/prefixmapper/pom.xml +25 -3
- data/data/libphonenumber/java/libphonenumber/pom.xml +23 -2
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/MetadataLoader.java +2 -1
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/MultiFileMetadataSourceImpl.java +63 -70
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberAlternateFormatsProto_595 +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_AZ +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BD +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BG +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BH +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HK +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_HN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KW +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_LV +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_PY +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SK +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TC +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TH +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TJ +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TZ +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_US +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_AE +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_AR +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_BR +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_GB +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_IN +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_NO +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_SK +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_ZA +0 -0
- data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/SingleFilePhoneNumberMetadataProto +0 -0
- data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/MultiFileMetadataSourceImplTest.java +25 -5
- data/data/libphonenumber/java/pom.xml +2 -2
- data/data/libphonenumber/java/release_notes.txt +45 -0
- data/data/libphonenumber/javascript/i18n/phonenumbers/demo-compiled.js +72 -70
- data/data/libphonenumber/javascript/i18n/phonenumbers/metadata.js +38 -32
- data/data/libphonenumber/javascript/i18n/phonenumbers/metadatalite.js +38 -32
- data/data/libphonenumber/resources/PhoneNumberAlternateFormats.xml +16 -0
- data/data/libphonenumber/resources/PhoneNumberMetadata.xml +232 -96
- data/data/libphonenumber/resources/ShortNumberMetadata.xml +188 -44
- data/data/libphonenumber/resources/carrier/en/255.txt +2 -0
- data/data/libphonenumber/resources/carrier/en/374.txt +3 -3
- data/data/libphonenumber/resources/carrier/en/421.txt +1 -0
- data/data/libphonenumber/resources/carrier/en/66.txt +1 -0
- data/data/libphonenumber/resources/carrier/en/91.txt +419 -253
- data/data/libphonenumber/resources/carrier/en/973.txt +1 -0
- data/data/libphonenumber/resources/carrier/en/992.txt +1 -0
- data/data/libphonenumber/resources/carrier/en/994.txt +3 -0
- data/data/libphonenumber/resources/carrier/fa/93.txt +24 -0
- data/data/libphonenumber/resources/carrier/fa/98.txt +30 -0
- data/data/libphonenumber/resources/carrier/ru/374.txt +28 -0
- data/data/libphonenumber/resources/geocoding/bg/82.txt +34 -0
- data/data/libphonenumber/resources/geocoding/ca/82.txt +34 -0
- data/data/libphonenumber/resources/geocoding/el/82.txt +28 -0
- data/data/libphonenumber/resources/geocoding/en/1.txt +2 -0
- data/data/libphonenumber/resources/geocoding/en/371.txt +3 -0
- data/data/libphonenumber/resources/geocoding/en/44.txt +19 -1
- data/data/libphonenumber/resources/geocoding/en/504.txt +19 -0
- data/data/libphonenumber/resources/geocoding/en/91.txt +1 -5
- data/data/libphonenumber/resources/geocoding/en/93.txt +52 -0
- data/data/libphonenumber/resources/geocoding/en/98.txt +0 -2
- data/data/libphonenumber/resources/geocoding/en/992.txt +77 -0
- data/data/libphonenumber/resources/geocoding/en/994.txt +98 -0
- data/data/libphonenumber/resources/geocoding/es/82.txt +33 -0
- data/data/libphonenumber/resources/geocoding/fa/93.txt +53 -0
- data/data/libphonenumber/resources/geocoding/fa/98.txt +0 -2
- data/data/libphonenumber/resources/geocoding/fi/82.txt +34 -0
- data/data/libphonenumber/resources/geocoding/hi/82.txt +36 -0
- data/data/libphonenumber/resources/geocoding/hu/82.txt +35 -0
- data/data/libphonenumber/resources/geocoding/iw/82.txt +37 -0
- data/data/libphonenumber/resources/geocoding/ja/82.txt +35 -0
- data/data/libphonenumber/resources/geocoding/tr/82.txt +35 -0
- data/data/libphonenumber/tools/java/common/pom.xml +2 -0
- data/data/libphonenumber/tools/java/cpp-build/pom.xml +4 -0
- data/data/libphonenumber/tools/java/data/pom.xml +1 -11
- data/data/libphonenumber/tools/java/java-build/pom.xml +2 -0
- data/data/phone_data.dat +0 -0
- data/lib/phonelib.rb +7 -6
- data/lib/phonelib/core.rb +116 -68
- data/lib/phonelib/data_importer.rb +23 -19
- data/lib/phonelib/data_importer_helper.rb +16 -16
- data/lib/phonelib/phone.rb +47 -137
- data/lib/phonelib/phone_analyzer.rb +27 -25
- data/lib/phonelib/phone_analyzer_helper.rb +16 -9
- data/lib/phonelib/phone_extended_data.rb +27 -17
- data/lib/phonelib/phone_formatter.rb +131 -0
- data/lib/phonelib/version.rb +2 -3
- data/lib/tasks/phonelib_tasks.rake +0 -2
- data/lib/validators/phone_validator.rb +24 -14
- metadata +42 -3
@@ -47,15 +47,12 @@
|
|
47
47
|
<plugin>
|
48
48
|
<groupId>org.apache.maven.plugins</groupId>
|
49
49
|
<artifactId>maven-compiler-plugin</artifactId>
|
50
|
+
<version>2.0.2</version>
|
50
51
|
<configuration>
|
51
52
|
<source>1.6</source>
|
52
53
|
<target>1.6</target>
|
53
54
|
</configuration>
|
54
55
|
</plugin>
|
55
|
-
<plugin>
|
56
|
-
<groupId>net.kindleit</groupId>
|
57
|
-
<artifactId>maven-gae-plugin</artifactId>
|
58
|
-
</plugin>
|
59
56
|
<plugin>
|
60
57
|
<groupId>org.apache.maven.plugins</groupId>
|
61
58
|
<artifactId>maven-assembly-plugin</artifactId>
|
@@ -80,13 +77,6 @@
|
|
80
77
|
</execution>
|
81
78
|
</executions>
|
82
79
|
</plugin>
|
83
|
-
<plugin>
|
84
|
-
<groupId>org.apache.maven.plugins</groupId>
|
85
|
-
<artifactId>maven-war-plugin</artifactId>
|
86
|
-
<configuration>
|
87
|
-
<warSourceDirectory>webapp</warSourceDirectory>
|
88
|
-
</configuration>
|
89
|
-
</plugin>
|
90
80
|
<plugin>
|
91
81
|
<groupId>org.mortbay.jetty</groupId>
|
92
82
|
<artifactId>maven-jetty-plugin</artifactId>
|
@@ -43,6 +43,7 @@
|
|
43
43
|
<plugin>
|
44
44
|
<groupId>org.apache.maven.plugins</groupId>
|
45
45
|
<artifactId>maven-compiler-plugin</artifactId>
|
46
|
+
<version>2.0.2</version>
|
46
47
|
<configuration>
|
47
48
|
<source>1.5</source>
|
48
49
|
<target>1.5</target>
|
@@ -51,6 +52,7 @@
|
|
51
52
|
<plugin>
|
52
53
|
<groupId>org.codehaus.mojo</groupId>
|
53
54
|
<artifactId>build-helper-maven-plugin</artifactId>
|
55
|
+
<version>1.9.1</version>
|
54
56
|
<executions>
|
55
57
|
<execution>
|
56
58
|
<id>add-source</id>
|
data/data/phone_data.dat
CHANGED
Binary file
|
data/lib/phonelib.rb
CHANGED
@@ -1,15 +1,16 @@
|
|
1
|
-
# main module definition
|
1
|
+
# main Phonelib module definition
|
2
2
|
module Phonelib
|
3
|
-
# load
|
3
|
+
# load phonelib classes/modules
|
4
4
|
autoload :Core, 'phonelib/core'
|
5
5
|
autoload :Phone, 'phonelib/phone'
|
6
|
+
autoload :PhoneFormatter, 'phonelib/phone_formatter'
|
6
7
|
autoload :PhoneAnalyzer, 'phonelib/phone_analyzer'
|
7
8
|
autoload :PhoneAnalyzerHelper, 'phonelib/phone_analyzer_helper'
|
8
9
|
autoload :PhoneExtendedData, 'phonelib/phone_extended_data'
|
9
10
|
|
10
|
-
extend
|
11
|
-
include Core
|
12
|
-
}
|
11
|
+
extend Core
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
if defined?(ActiveModel) || defined?(Rails)
|
15
|
+
autoload :PhoneValidator, 'validators/phone_validator'
|
16
|
+
end
|
data/lib/phonelib/core.rb
CHANGED
@@ -1,191 +1,222 @@
|
|
1
1
|
module Phonelib
|
2
2
|
# main module that includes all basic data and methods
|
3
3
|
module Core
|
4
|
-
# variable will include hash with data for validation
|
4
|
+
# @private variable will include hash with data for validation
|
5
5
|
@@phone_data = nil
|
6
6
|
|
7
7
|
# getter for phone data for other modules of gem, can be used outside
|
8
|
+
# @return [Hash] all data for phone parsing
|
8
9
|
def phone_data
|
9
10
|
@@phone_data ||= load_data.freeze
|
10
11
|
end
|
11
12
|
|
12
|
-
# used to cache frequently-used regular expressions
|
13
|
+
# @private used to cache frequently-used regular expressions
|
13
14
|
@@phone_regexp_cache = {}
|
14
15
|
|
15
|
-
# getter for phone regexp cache (internal use only)
|
16
|
+
# @private getter for phone regexp cache (internal use only)
|
16
17
|
def phone_regexp_cache
|
17
18
|
@@phone_regexp_cache
|
18
19
|
end
|
19
20
|
|
20
|
-
# variable for storing geo/carrier/timezone data
|
21
|
+
# @private variable for storing geo/carrier/timezone data
|
21
22
|
@@phone_ext_data = nil
|
22
23
|
|
23
|
-
# getter for extended phone data
|
24
|
+
# @private getter for extended phone data
|
24
25
|
def phone_ext_data
|
25
26
|
@@phone_ext_data ||= load_ext_data.freeze
|
26
27
|
end
|
27
28
|
|
28
|
-
# default country for parsing variable setting
|
29
|
+
# @private default country for parsing variable setting
|
29
30
|
@@default_country = nil
|
30
31
|
|
31
32
|
# getter method for default_country variable
|
33
|
+
# @return [String|nil] Default country set for parsing or nil
|
32
34
|
def default_country
|
33
35
|
@@default_country
|
34
36
|
end
|
35
37
|
|
36
38
|
# setter method for default_country variable
|
39
|
+
# @param country [String|Symbol] default country ISO2 code used for parsing
|
40
|
+
# @return [String|nil] Default country set for parsing or nil
|
37
41
|
def default_country=(country)
|
38
42
|
@@default_country = country
|
39
43
|
end
|
40
44
|
|
41
|
-
# extension separator
|
45
|
+
# @private extension separator
|
42
46
|
@@extension_separator = ';'
|
43
47
|
|
44
48
|
# getter method for extension_separator variable
|
49
|
+
# @return [String] Default extension separator used for formatting
|
45
50
|
def extension_separator
|
46
51
|
@@extension_separator
|
47
52
|
end
|
48
53
|
|
49
54
|
# setter method for extension_separator variable
|
55
|
+
# @param separator [String] extension separator used for formatting
|
56
|
+
# @return [String] Default extension separator used for formatting
|
50
57
|
def extension_separator=(separator)
|
51
58
|
@@extension_separator = separator
|
52
59
|
end
|
53
60
|
|
54
|
-
# extension separator symbols for parsing
|
61
|
+
# @private extension separator symbols for parsing
|
55
62
|
@@extension_separate_symbols = '#;'
|
56
63
|
|
57
64
|
# getter method for extension_separate_symbols variable
|
65
|
+
# @return [String] Default extension separator symbols used for parsing
|
58
66
|
def extension_separate_symbols
|
59
67
|
@@extension_separate_symbols
|
60
68
|
end
|
61
69
|
|
62
70
|
# setter method for extension_separate_symbols variable
|
71
|
+
# @param separator [String] extension separator symbols used for parsing
|
72
|
+
# @return [String] Default extension separator symbols used for parsing
|
63
73
|
def extension_separate_symbols=(separator)
|
64
74
|
@@extension_separate_symbols = separator
|
65
75
|
end
|
66
76
|
|
67
|
-
# flag identifies whether to use special phone types,
|
77
|
+
# @private flag identifies whether to use special phone types, \
|
78
|
+
# like short code
|
68
79
|
@@parse_special = false
|
69
80
|
|
70
81
|
# getter for flag for special phone types parsing
|
82
|
+
# @return [Boolean] Flag defines whether to parse special phone types
|
71
83
|
def parse_special
|
72
84
|
@@parse_special
|
73
85
|
end
|
74
86
|
|
75
87
|
# setter for flag for special phone types parsing
|
88
|
+
# @param special [Boolean] parse special phone types value
|
89
|
+
# @return [Boolean] Flag defines whether to parse special phone types
|
76
90
|
def parse_special=(special)
|
77
91
|
@@parse_special = special
|
78
92
|
end
|
79
93
|
|
80
|
-
# strict check for validator, doesn't sanitize number
|
94
|
+
# @private strict check for validator, doesn't sanitize number
|
81
95
|
@@strict_check = false
|
82
96
|
|
83
97
|
# getter for strict check flag
|
98
|
+
# @return [Boolean] Flag defines whether to do strict parsing check
|
84
99
|
def strict_check
|
85
100
|
@@strict_check
|
86
101
|
end
|
87
102
|
|
88
103
|
# setter for strict check flag
|
104
|
+
# @param strict [Boolean] make a strict parsing or not
|
105
|
+
# @return [Boolean] Flag defines whether to do strict parsing check
|
89
106
|
def strict_check=(strict)
|
90
107
|
@@strict_check = strict
|
91
108
|
end
|
92
109
|
|
93
110
|
# gem constants definition
|
94
111
|
|
95
|
-
# Main data file
|
112
|
+
# @private Main data file
|
96
113
|
FILE_MAIN_DATA = 'data/phone_data.dat'
|
97
|
-
# Extended data file
|
114
|
+
# @private Extended data file
|
98
115
|
FILE_EXT_DATA = 'data/extended_data.dat'
|
99
116
|
|
100
117
|
# constants for phone types
|
101
118
|
|
102
119
|
# Validation patterns keys constants
|
103
|
-
# General pattern for country key
|
120
|
+
# @private General pattern for country key
|
104
121
|
GENERAL = :general_desc
|
105
|
-
# Freephone line pattern key
|
122
|
+
# @private Freephone line pattern key
|
106
123
|
PREMIUM_RATE = :premium_rate
|
107
|
-
# Freephone line pattern key
|
124
|
+
# @private Freephone line pattern key
|
108
125
|
TOLL_FREE = :toll_free
|
109
|
-
# Shared cost pattern key. The cost of this call is shared
|
110
|
-
# and recipient, and is hence typically less than
|
126
|
+
# @private Shared cost pattern key. The cost of this call is shared
|
127
|
+
# between caller and recipient, and is hence typically less than
|
128
|
+
# PREMIUM_RATE calls
|
111
129
|
SHARED_COST = :shared_cost
|
112
|
-
# VoIP pattern key. This includes TSoIP (Telephony Service over IP)
|
130
|
+
# @private VoIP pattern key. This includes TSoIP (Telephony Service over IP)
|
113
131
|
VOIP = :voip
|
114
|
-
# A personal number is associated with a particular person,
|
115
|
-
# routed to either a MOBILE or FIXED_LINE number.
|
132
|
+
# @private A personal number is associated with a particular person,
|
133
|
+
# and may be routed to either a MOBILE or FIXED_LINE number.
|
116
134
|
PERSONAL_NUMBER = :personal_number
|
117
|
-
# Pager phone number pattern key
|
135
|
+
# @private Pager phone number pattern key
|
118
136
|
PAGER = :pager
|
119
|
-
# Used for 'Universal Access Numbers' or 'Company Numbers'.
|
120
|
-
# further routed to specific offices, but allow one number
|
121
|
-
# company.
|
137
|
+
# @private Used for 'Universal Access Numbers' or 'Company Numbers'.
|
138
|
+
# They may be further routed to specific offices, but allow one number
|
139
|
+
# to be used for a company.
|
122
140
|
UAN = :uan
|
123
|
-
# Used for 'Voice Mail Access Numbers'.
|
141
|
+
# @private Used for 'Voice Mail Access Numbers'.
|
124
142
|
VOICEMAIL = :voicemail
|
125
|
-
# Fixed line pattern key
|
143
|
+
# @private Fixed line pattern key
|
126
144
|
FIXED_LINE = :fixed_line
|
127
|
-
# Mobile phone number pattern key
|
145
|
+
# @private Mobile phone number pattern key
|
128
146
|
MOBILE = :mobile
|
129
|
-
# In case MOBILE and FIXED patterns are the same,
|
147
|
+
# @private In case MOBILE and FIXED patterns are the same,
|
148
|
+
# this type is returned
|
130
149
|
FIXED_OR_MOBILE = :fixed_or_mobile
|
131
|
-
# Short code
|
150
|
+
# @private Short code
|
132
151
|
SHORT_CODE = :short_code
|
133
|
-
# emergency numbers
|
152
|
+
# @private emergency numbers
|
134
153
|
EMERGENCY = :emergency
|
135
|
-
# carrier specific type
|
154
|
+
# @private carrier specific type
|
136
155
|
CARRIER_SPECIFIC = :carrier_specific
|
137
|
-
# SMS Services only type
|
156
|
+
# @private SMS Services only type
|
138
157
|
SMS_SERVICES = :sms_services
|
139
|
-
# expendad emergency type
|
158
|
+
# @private expendad emergency type
|
140
159
|
EXPANDED_EMERGENCY = :expanded_emergency
|
141
|
-
# no international dialling type
|
160
|
+
# @private no international dialling type
|
142
161
|
NO_INTERNATIONAL_DIALING = :no_international_dialling
|
143
|
-
# carrier services type
|
162
|
+
# @private carrier services type
|
144
163
|
CARRIER_SERVICES = :carrier_services
|
145
|
-
# directory services
|
164
|
+
# @private directory services
|
146
165
|
DIRECTORY_SERVICES = :directory_services
|
147
|
-
# standard rate type
|
166
|
+
# @private standard rate type
|
148
167
|
STANDARD_RATE = :standard_rate
|
149
|
-
# carrier selection codes
|
168
|
+
# @private carrier selection codes
|
150
169
|
CARRIER_SELECTION_CODES = :carrier_selection_codes
|
151
|
-
# area code optional type
|
170
|
+
# @private area code optional type
|
152
171
|
AREA_CODE_OPTIONAL = :area_code_optional
|
153
172
|
|
154
173
|
# Internal use keys for validations
|
155
|
-
# Valid regex pattern key
|
174
|
+
# @private Valid regex pattern key
|
156
175
|
VALID_PATTERN = :national_number_pattern
|
157
|
-
# Possible regex pattern key
|
176
|
+
# @private Possible regex pattern key
|
158
177
|
POSSIBLE_PATTERN = :possible_number_pattern
|
159
|
-
# National prefix key
|
178
|
+
# @private National prefix key
|
160
179
|
NATIONAL_PREFIX = :national_prefix
|
161
|
-
# National prefix for parsing key
|
180
|
+
# @private National prefix for parsing key
|
162
181
|
NATIONAL_PREFIX_FOR_PARSING = :national_prefix_for_parsing
|
163
|
-
# National prefix rule key
|
182
|
+
# @private National prefix rule key
|
164
183
|
NATIONAL_PREFIX_RULE = :national_prefix_formatting_rule
|
165
|
-
# Country code key
|
184
|
+
# @private Country code key
|
166
185
|
COUNTRY_CODE = :country_code
|
167
|
-
# Leading digits key
|
186
|
+
# @private Leading digits key
|
168
187
|
LEADING_DIGITS = :leading_digits
|
169
|
-
# International prefix key
|
188
|
+
# @private International prefix key
|
170
189
|
INTERNATIONAL_PREFIX = :international_prefix
|
171
|
-
# Main country for code key
|
190
|
+
# @private Main country for code key
|
172
191
|
MAIN_COUNTRY_FOR_CODE = :main_country_for_code
|
173
|
-
# Double country prefix flag key
|
192
|
+
# @private Double country prefix flag key
|
174
193
|
DOUBLE_COUNTRY_PREFIX_FLAG = :double_prefix
|
175
|
-
# Types key
|
194
|
+
# @private Types key
|
176
195
|
TYPES = :types
|
177
|
-
# Formats key
|
196
|
+
# @private Formats key
|
178
197
|
FORMATS = :formats
|
179
|
-
# Pattern key
|
198
|
+
# @private Pattern key
|
180
199
|
PATTERN = :pattern
|
181
200
|
|
182
|
-
#
|
201
|
+
# @private Area code possible types
|
202
|
+
AREA_CODE_TYPES = [FIXED_LINE, FIXED_OR_MOBILE, MOBILE]
|
203
|
+
|
204
|
+
# @private Area code countries for mobile type
|
205
|
+
AREA_CODE_MOBILE_COUNTRIES = %w(AR MX BR)
|
206
|
+
|
207
|
+
# @private Area code mobile phone token
|
208
|
+
AREA_CODE_MOBILE_TOKENS = {
|
209
|
+
'MX' => '1',
|
210
|
+
'AR' => '9'
|
211
|
+
}
|
212
|
+
|
213
|
+
# @private Default number formatting data hash
|
183
214
|
DEFAULT_NUMBER_FORMAT = {
|
184
215
|
pattern: '(\\d+)(\\d{3})(\\d{4})',
|
185
216
|
format: '$1 $2 $3'
|
186
217
|
}
|
187
218
|
|
188
|
-
# hash of all phone types with human representation
|
219
|
+
# @private hash of all phone types with human representation
|
189
220
|
TYPES_DESC = {
|
190
221
|
general_desc: 'General Pattern',
|
191
222
|
premium_rate: 'Premium Rate',
|
@@ -212,74 +243,91 @@ module Phonelib
|
|
212
243
|
area_code_optional: 'Are code optional'
|
213
244
|
}
|
214
245
|
|
215
|
-
# short codes types keys
|
246
|
+
# @private short codes types keys
|
216
247
|
SHORT_CODES = [
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
248
|
+
:short_code, :emergency, :carrier_specific, :sms_services,
|
249
|
+
:expanded_emergency, :no_international_dialling, :carrier_services,
|
250
|
+
:directory_services, :standard_rate, :carrier_selection_codes,
|
251
|
+
:area_code_optional
|
221
252
|
]
|
222
253
|
|
223
|
-
# Extended data prefixes hash key
|
254
|
+
# @private Extended data prefixes hash key
|
224
255
|
EXT_PREFIXES = :prefixes
|
225
|
-
# Extended data geo names array key
|
256
|
+
# @private Extended data geo names array key
|
226
257
|
EXT_GEO_NAMES = :geo_names
|
227
|
-
# Extended data timezones array key
|
258
|
+
# @private Extended data timezones array key
|
228
259
|
EXT_TIMEZONES = :timezones
|
229
|
-
# Extended data carriers array key
|
260
|
+
# @private Extended data carriers array key
|
230
261
|
EXT_CARRIERS = :carriers
|
231
|
-
# Extended data key for geoname in prefixes hash
|
262
|
+
# @private Extended data key for geoname in prefixes hash
|
232
263
|
EXT_GEO_NAME_KEY = :g
|
233
|
-
# Extended data key for timezone in prefixes hash
|
264
|
+
# @private Extended data key for timezone in prefixes hash
|
234
265
|
EXT_TIMEZONE_KEY = :t
|
235
|
-
# Extended data key for carrier in prefixes hash
|
266
|
+
# @private Extended data key for carrier in prefixes hash
|
236
267
|
EXT_CARRIER_KEY = :c
|
237
268
|
|
238
269
|
# method for parsing phone number.
|
239
270
|
# On first run fills @@phone_data with data present in yaml file
|
271
|
+
# @param phone [String] the phone number to be parsed
|
272
|
+
# @param passed_country [nil|String|Symbol] country for phone parsing
|
273
|
+
# @return [Phonelib::Phone] parsed phone entity
|
240
274
|
def parse(phone, passed_country = nil)
|
241
275
|
Phonelib::Phone.new phone, passed_country
|
242
276
|
end
|
243
277
|
|
244
278
|
# method checks if passed phone number is valid
|
279
|
+
# @param phone_number [String] the phone number to be parsed
|
280
|
+
# @return [Boolean] phone valid or not
|
245
281
|
def valid?(phone_number)
|
246
282
|
parse(phone_number).valid?
|
247
283
|
end
|
248
284
|
|
249
285
|
# method checks if passed phone number is invalid
|
286
|
+
# @param phone_number [String] the phone number to be parsed
|
287
|
+
# @return [Boolean] phone invalid or not
|
250
288
|
def invalid?(phone_number)
|
251
289
|
parse(phone_number).invalid?
|
252
290
|
end
|
253
291
|
|
254
292
|
# method checks if passed phone number is possible
|
293
|
+
# @param phone_number [String] the phone number to be parsed
|
294
|
+
# @return [Boolean] phone possible or not
|
255
295
|
def possible?(phone_number)
|
256
296
|
parse(phone_number).possible?
|
257
297
|
end
|
258
298
|
|
259
299
|
# method checks if passed phone number is impossible
|
300
|
+
# @param phone_number [String] the phone number to be parsed
|
301
|
+
# @return [Boolean] phone impossible or not
|
260
302
|
def impossible?(phone_number)
|
261
303
|
parse(phone_number).impossible?
|
262
304
|
end
|
263
305
|
|
264
306
|
# method checks if passed phone number is valid for provided country
|
307
|
+
# @param phone_number [String] the phone number to be parsed
|
308
|
+
# @param country [String] ISO2 country code for phone parsing
|
309
|
+
# @return [Boolean] phone valid for specified country or not
|
265
310
|
def valid_for_country?(phone_number, country)
|
266
311
|
parse(phone_number, country).valid_for_country?(country)
|
267
312
|
end
|
268
313
|
|
269
314
|
# method checks if passed phone number is invalid for provided country
|
315
|
+
# @param phone_number [String] the phone number to be parsed
|
316
|
+
# @param country [String] ISO2 country code for phone parsing
|
317
|
+
# @return [Boolean] phone invalid for specified country or not
|
270
318
|
def invalid_for_country?(phone_number, country)
|
271
319
|
parse(phone_number, country).invalid_for_country?(country)
|
272
320
|
end
|
273
321
|
|
274
322
|
private
|
275
323
|
|
276
|
-
# Load data file into memory
|
324
|
+
# @private Load data file into memory
|
277
325
|
def load_data
|
278
326
|
data_file = "#{File.dirname(__FILE__)}/../../#{FILE_MAIN_DATA}"
|
279
327
|
Marshal.load(File.binread(data_file))
|
280
328
|
end
|
281
329
|
|
282
|
-
# Load extended data file into memory
|
330
|
+
# @private Load extended data file into memory
|
283
331
|
def load_ext_data
|
284
332
|
data_file = "#{File.dirname(__FILE__)}/../../#{FILE_EXT_DATA}"
|
285
333
|
Marshal.load(File.binread(data_file))
|