phonelib 0.10.5 → 0.10.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91ac6f0678295402a73fbefd2e073f04a4fff9240c6fa4f93dbde0bccfe11014
4
- data.tar.gz: d9fa26fa4d55bad564e0002ac17694ec20ce59ac5d8a1b20752bdcc6d97ce32c
3
+ metadata.gz: c3392c3861bbde37edc22277490262ba9575e3fece9af25cc905e7e9818c3dfe
4
+ data.tar.gz: 341900031e760af19a6ab4f0e00dc7fd1f5d9df54fd3e8489428cefd4f070f42
5
5
  SHA512:
6
- metadata.gz: 8dd3cdc933f0f820f59eddd5bce35d4d81ec9b8c52085498f0750769a73fecb07f9522a97cfd59e27b29a766f19c422e2f571d59d6488b26898ae34b6fb2a099
7
- data.tar.gz: f8c549c48c8d0695c1a204c03cf4cc0189d9a408b72a8bae005b4996eefdf666fdcaa4a4d707849cd51e34ee33e41637845cfa01c8da4225b07bb7de795df3c7
6
+ metadata.gz: aca95b93fc79099532429253cc5a395e1570b9fa18cf59c52e1c531830cc0664b95c3ed9380d54fb831e517bd78bb4dfcb6a35a7d766a4fd2322d33c1641136d
7
+ data.tar.gz: 5e2f46e9ba85cdd56f66b48b9edd731229be5f676ba6087a531ec2cf14ed8b8cbc477c17a201b1bae42b4873751a4cd6335f2a118cbb881a3a2bf98095ee3bd0
Binary file
data/data/phone_data.dat CHANGED
Binary file
@@ -138,7 +138,10 @@ module Phonelib
138
138
  countries_data.each_with_object({}) do |data, result|
139
139
  key = data[:id]
140
140
  parsed = parse_single_country(phone, data)
141
- parsed = parse_single_country(with_replaced_national_prefix(phone, data), data) unless parsed && parsed[key] && parsed[key][:valid].size > 0
141
+ unless parsed && parsed[key] && parsed[key][:valid].size > 0
142
+ replaced_parsed = parse_single_country(with_replaced_national_prefix(phone, data), data)
143
+ parsed = replaced_parsed unless replaced_parsed.nil?
144
+ end
142
145
  if (!Phonelib.strict_double_prefix_check || key == country) && double_prefix_allowed?(data, phone, parsed && parsed[key])
143
146
  parsed2 = parse_single_country(changed_dp_phone(key, phone), data)
144
147
  parsed = parsed2 if parsed2 && parsed2[key] && parsed2[key][:valid].size > 0
@@ -159,13 +162,13 @@ module Phonelib
159
162
  # * +phone+ - phone number for parsing
160
163
  # * +data+ - country data to be based on for creating e164 representation
161
164
  def convert_to_e164(phone, data)
162
- match = phone.match full_regex_for_data(data, Core::VALID_PATTERN, !original_starts_with_plus?)
165
+ match = phone.match full_regex_for_data(data, Core::VALID_PATTERN, !original_starts_with_plus_or_double_zero?)
163
166
  case
164
167
  when match
165
168
  "#{data[Core::COUNTRY_CODE]}#{match.to_a.last}"
166
169
  when phone.match(cr("^#{data[Core::INTERNATIONAL_PREFIX]}"))
167
170
  phone.sub(cr("^#{data[Core::INTERNATIONAL_PREFIX]}"), Core::PLUS_SIGN)
168
- when original_starts_with_plus? && phone.start_with?(data[Core::COUNTRY_CODE])
171
+ when original_starts_with_plus_or_double_zero? && phone.start_with?(data[Core::COUNTRY_CODE])
169
172
  phone
170
173
  else
171
174
  "#{data[Core::COUNTRY_CODE]}#{phone}"
@@ -16,8 +16,8 @@ module Phonelib
16
16
  end
17
17
  end
18
18
 
19
- def original_starts_with_plus?
20
- original_s[0] == Core::PLUS_SIGN
19
+ def original_starts_with_plus_or_double_zero?
20
+ original_s[0] == Core::PLUS_SIGN || original_s[0..1] == '00'
21
21
  end
22
22
 
23
23
  # converts symbols in phone to numbers
@@ -61,7 +61,8 @@ module Phonelib
61
61
  def country_can_dp?(country)
62
62
  Phonelib.phone_data[country] &&
63
63
  Phonelib.phone_data[country][Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
64
- !original_starts_with_plus? && original_s.start_with?(Phonelib.phone_data[country][Core::COUNTRY_CODE])
64
+ !original_starts_with_plus_or_double_zero? &&
65
+ original_s.start_with?(Phonelib.phone_data[country][Core::COUNTRY_CODE])
65
66
  end
66
67
 
67
68
  # changes phone to with/without double country prefix
@@ -89,7 +90,7 @@ module Phonelib
89
90
  data[Core::DOUBLE_COUNTRY_PREFIX_FLAG] &&
90
91
  phone =~ cr("^#{data[Core::COUNTRY_CODE]}") &&
91
92
  parsed && (parsed[:valid].nil? || parsed[:valid].empty?) &&
92
- !original_starts_with_plus?
93
+ !original_starts_with_plus_or_double_zero?
93
94
  end
94
95
 
95
96
  # Returns original number passed if it's a string or empty string otherwise
@@ -103,7 +104,8 @@ module Phonelib
103
104
  #
104
105
  # * +country+ - country passed for parsing
105
106
  def country_or_default_country(country)
106
- country ||= (original_starts_with_plus? ? nil : Phonelib.default_country)
107
+ country ||= (original_starts_with_plus_or_double_zero? ? nil : Phonelib.default_country)
108
+
107
109
  if country.is_a?(Array)
108
110
  country.compact.map { |e| e.to_s.upcase }
109
111
  else
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Phonelib
4
4
  # @private
5
- VERSION = '0.10.5'
5
+ VERSION = '0.10.7'
6
6
  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.10.5
4
+ version: 0.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Senderovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-02-24 00:00:00.000000000 Z
11
+ date: 2025-04-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |2
14
14
  Google libphonenumber library was taken as a basis for
@@ -40,7 +40,7 @@ homepage: https://github.com/daddyz/phonelib
40
40
  licenses:
41
41
  - MIT
42
42
  metadata:
43
- changelog_uri: https://github.com/daddyz/phonelib/releases/tag/v0.10.5
43
+ changelog_uri: https://github.com/daddyz/phonelib/releases/tag/v0.10.7
44
44
  post_install_message:
45
45
  rdoc_options:
46
46
  - " --no-private - CHANGELOG.md --readme README.md"