phonelib 0.5.6 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/data/extended_data.dat +0 -0
  3. data/data/libphonenumber/FALSEHOODS.md +221 -0
  4. data/data/libphonenumber/FAQ.md +8 -0
  5. data/data/libphonenumber/README.md +4 -4
  6. data/data/libphonenumber/cpp/CMakeLists.txt +2 -1
  7. data/data/libphonenumber/cpp/README +62 -2
  8. data/data/libphonenumber/cpp/src/phonenumbers/lite_metadata.cc +9480 -9440
  9. data/data/libphonenumber/cpp/src/phonenumbers/metadata.cc +10349 -10308
  10. data/data/libphonenumber/cpp/src/phonenumbers/phonenumbermatcher.cc +1 -1
  11. data/data/libphonenumber/cpp/src/phonenumbers/phonenumberutil.cc +108 -5
  12. data/data/libphonenumber/cpp/src/phonenumbers/phonenumberutil.h +37 -4
  13. data/data/libphonenumber/cpp/src/phonenumbers/short_metadata.cc +544 -514
  14. data/data/libphonenumber/cpp/test/phonenumbers/phonenumbermatcher_test.cc +9 -1
  15. data/data/libphonenumber/cpp/test/phonenumbers/phonenumberutil_test.cc +61 -1
  16. data/data/libphonenumber/debian/control +1 -1
  17. data/data/libphonenumber/java/carrier/pom.xml +4 -4
  18. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/225_en +0 -0
  19. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/229_en +0 -0
  20. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/252_en +0 -0
  21. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/254_en +0 -0
  22. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/84_en +0 -0
  23. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/853_en +0 -0
  24. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/86_en +0 -0
  25. data/data/libphonenumber/java/carrier/src/com/google/i18n/phonenumbers/carrier/data/968_en +0 -0
  26. data/data/libphonenumber/java/demo/pom.xml +5 -5
  27. data/data/libphonenumber/java/geocoder/pom.xml +4 -4
  28. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/251_en +0 -0
  29. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/254_en +0 -0
  30. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/84_en +0 -0
  31. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_en +0 -0
  32. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/geocoding/data/86_zh +0 -0
  33. data/data/libphonenumber/java/geocoder/src/com/google/i18n/phonenumbers/timezones/data/map_data +0 -0
  34. data/data/libphonenumber/java/internal/prefixmapper/pom.xml +3 -3
  35. data/data/libphonenumber/java/libphonenumber/pom.xml +2 -2
  36. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/PhoneNumberUtil.java +120 -12
  37. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BJ +0 -0
  38. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_BZ +0 -0
  39. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CI +0 -0
  40. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CL +0 -0
  41. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_CN +0 -0
  42. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ET +0 -0
  43. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_FO +0 -0
  44. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_GQ +0 -0
  45. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_IN +0 -0
  46. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KE +0 -0
  47. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_KW +0 -0
  48. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_ML +0 -0
  49. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_MO +0 -0
  50. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_NO +0 -0
  51. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_OM +0 -0
  52. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SE +0 -0
  53. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_SO +0 -0
  54. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_TK +0 -0
  55. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProto_VN +0 -0
  56. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_FO +0 -0
  57. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_FR +0 -0
  58. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/ShortNumberMetadataProto_KE +0 -0
  59. data/data/libphonenumber/java/libphonenumber/src/com/google/i18n/phonenumbers/data/SingleFilePhoneNumberMetadataProto +0 -0
  60. data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/ExampleNumbersTest.java +22 -4
  61. data/data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/PhoneNumberUtilTest.java +22 -1
  62. data/data/libphonenumber/java/pending_code_changes.txt +1 -0
  63. data/data/libphonenumber/java/pom.xml +1 -1
  64. data/data/libphonenumber/java/release_notes.txt +33 -1
  65. data/data/libphonenumber/javascript/README.md +2 -2
  66. data/data/libphonenumber/javascript/i18n/phonenumbers/demo-compiled.js +157 -155
  67. data/data/libphonenumber/javascript/i18n/phonenumbers/metadata.js +49 -41
  68. data/data/libphonenumber/javascript/i18n/phonenumbers/metadatalite.js +49 -41
  69. data/data/libphonenumber/javascript/i18n/phonenumbers/phonenumberutil.js +39 -10
  70. data/data/libphonenumber/javascript/i18n/phonenumbers/phonenumberutil_test.js +8 -0
  71. data/data/libphonenumber/resources/PhoneNumberMetadata.xml +176 -125
  72. data/data/libphonenumber/resources/ShortNumberMetadata.xml +158 -24
  73. data/data/libphonenumber/resources/carrier/en/225.txt +1 -0
  74. data/data/libphonenumber/resources/carrier/en/229.txt +3 -0
  75. data/data/libphonenumber/resources/carrier/en/252.txt +1 -0
  76. data/data/libphonenumber/resources/carrier/en/254.txt +24 -8
  77. data/data/libphonenumber/resources/carrier/en/84.txt +3 -0
  78. data/data/libphonenumber/resources/carrier/en/853.txt +10 -0
  79. data/data/libphonenumber/resources/carrier/en/86.txt +9 -0
  80. data/data/libphonenumber/resources/carrier/en/968.txt +11 -1
  81. data/data/libphonenumber/resources/geocoding/en/251.txt +1 -0
  82. data/data/libphonenumber/resources/geocoding/en/254.txt +5 -5
  83. data/data/libphonenumber/resources/geocoding/en/84.txt +9 -1
  84. data/data/libphonenumber/resources/geocoding/en/86.txt +18 -14
  85. data/data/libphonenumber/resources/geocoding/zh/86.txt +17 -15
  86. data/data/libphonenumber/resources/phonenumber.proto +7 -6
  87. data/data/libphonenumber/resources/timezones/map_data.txt +63 -19
  88. data/data/phone_data.dat +0 -0
  89. data/lib/phonelib/phone_analyzer.rb +11 -7
  90. data/lib/phonelib/phone_analyzer_helper.rb +4 -3
  91. data/lib/phonelib/version.rb +1 -1
  92. metadata +4 -2
data/data/phone_data.dat CHANGED
Binary file
@@ -20,11 +20,11 @@ module Phonelib
20
20
 
21
21
  result = try_to_parse_single_country(phone, country)
22
22
  # if previous parsing failed, trying for all countries
23
- if result.nil? || result.empty? || result.values.first[:valid].empty?
23
+ if passed_country.nil? && (result.nil? || result.empty? || result.values.first[:valid].empty?)
24
24
  detected = detect_and_parse phone
25
25
  result = detected.empty? ? result || {} : detected
26
26
  end
27
- result
27
+ result || {}
28
28
  end
29
29
 
30
30
  private
@@ -64,7 +64,7 @@ module Phonelib
64
64
  get_national_and_data(e164, data, valid_match)
65
65
  else
66
66
  possible_match = phone_match_data?(e164, data, true)
67
- possible_match && get_national_and_data(e164, data, possible_match)
67
+ possible_match && get_national_and_data(e164, data, possible_match, true)
68
68
  end
69
69
  end
70
70
 
@@ -111,14 +111,17 @@ module Phonelib
111
111
  # * +phone+ - phone number for parsing
112
112
  # * +data+ - country data
113
113
  # * +country_match+ - result of match of phone within full regex
114
- def get_national_and_data(phone, data, country_match)
114
+ # * +not_valid+ - specifies that number is not valid by general desc pattern
115
+ def get_national_and_data(phone, data, country_match, not_valid = false)
115
116
  prefix_length = data[Core::COUNTRY_CODE].length
116
117
  prefix_length += [1, 2].map { |i| country_match[i].to_s.size }.inject(:+)
117
118
  result = data.select { |k, v| k != :types && k != :formats }
118
119
  result[:national] = phone[prefix_length..-1] || ''
119
120
  result[:format] = get_number_format(result[:national],
120
121
  data[Core::FORMATS])
121
- result.merge! all_number_types(result[:national], data[Core::TYPES])
122
+ result.merge! all_number_types(result[:national], data[Core::TYPES], not_valid)
123
+ result[:valid] = [] if not_valid
124
+
122
125
  { result[:id] => result }
123
126
  end
124
127
 
@@ -129,14 +132,15 @@ module Phonelib
129
132
  #
130
133
  # * +phone+ - phone number for parsing
131
134
  # * +data+ - country data
132
- def all_number_types(phone, data)
135
+ # * +not_valid+ - specifies that number is not valid by general desc pattern
136
+ def all_number_types(phone, data, not_valid = false)
133
137
  response = { valid: [], possible: [] }
134
138
 
135
139
  types_for_check(data).each do |type|
136
140
  possible, valid = get_patterns(data, type)
137
141
 
138
142
  valid_and_possible, possible_result =
139
- number_valid_and_possible?(phone, possible, valid)
143
+ number_valid_and_possible?(phone, possible, valid, not_valid)
140
144
  response[:possible] << type if possible_result
141
145
  response[:valid] << type if valid_and_possible
142
146
  end
@@ -111,13 +111,14 @@ module Phonelib
111
111
  # * +number+ - phone number for validation
112
112
  # * +possible_pattern+ - possible pattern for validation
113
113
  # * +national_pattern+ - valid pattern for validation
114
- def number_valid_and_possible?(number, possible_pattern, national_pattern)
114
+ # * +not_valid+ - specifies that number is not valid by general desc pattern
115
+ def number_valid_and_possible?(number, possible_pattern, national_pattern, not_valid = false)
115
116
  possible_match = number.match(cr("^(?:#{possible_pattern})$"))
116
117
  possible = possible_match && possible_match.to_s.length == number.length
117
118
 
118
- return [possible, possible] if possible_pattern == national_pattern
119
+ return [!not_valid && possible, possible] if possible_pattern == national_pattern
119
120
  valid = false
120
- if possible
121
+ if !not_valid && possible
121
122
  # doing national pattern match only in case possible matches
122
123
  national_match = number.match(cr("^(?:#{national_pattern})$"))
123
124
  valid = national_match && national_match.to_s.length == number.length
@@ -1,5 +1,5 @@
1
1
  # :nodoc:
2
2
  module Phonelib
3
3
  # :nodoc:
4
- VERSION = '0.5.6'
4
+ VERSION = '0.6.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: phonelib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.6
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Senderovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-07 00:00:00.000000000 Z
11
+ date: 2016-04-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -110,6 +110,7 @@ files:
110
110
  - data/libphonenumber/AUTHORS
111
111
  - data/libphonenumber/CONTRIBUTING.md
112
112
  - data/libphonenumber/CONTRIBUTORS
113
+ - data/libphonenumber/FALSEHOODS.md
113
114
  - data/libphonenumber/FAQ.md
114
115
  - data/libphonenumber/LICENSE
115
116
  - data/libphonenumber/LICENSE.Chromium
@@ -1579,6 +1580,7 @@ files:
1579
1580
  - data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_US
1580
1581
  - data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/data/PhoneNumberMetadataProtoForTesting_YT
1581
1582
  - data/libphonenumber/java/libphonenumber/test/com/google/i18n/phonenumbers/data/SingleFilePhoneNumberMetadataProtoForTesting
1583
+ - data/libphonenumber/java/pending_code_changes.txt
1582
1584
  - data/libphonenumber/java/pom.xml
1583
1585
  - data/libphonenumber/java/release_notes.txt
1584
1586
  - data/libphonenumber/javadoc/allclasses-frame.html