phonelib 0.6.19 → 0.6.20

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9249378077a22dab9790c7a3fa57052d973c82b
4
- data.tar.gz: 62ed0e7a587653648cf41c5d3e641ad2f52bbeaf
3
+ metadata.gz: e5f646f52d422a81f3c5661833bc8fbcd16d58d0
4
+ data.tar.gz: c95290c503448d13bcbc8155441cd3eaf79db473
5
5
  SHA512:
6
- metadata.gz: 7513f3968d272f53b6de993e975ee182fe469991906b05b788f4c9bac43be8864bddb325a964c6b56a1ea3648e44c07b085196227face176b69892ac693cec80
7
- data.tar.gz: 9e45a5cd7fdca6bec5786669b27347fb7bce3b2b6ece459f1ee698b15225bcbb4395a6b514dfeddbcbb4486e24745d110434ef7d4933ef02bd40816e88894aee
6
+ metadata.gz: 2081bdbc6d307b6443809a38f3a2bf5e928c7049095a113fe53583d9677f52c38a9b18d8df8b2818dec095abf84dc9d942fb433dd8c68457c745586a3dd304c7
7
+ data.tar.gz: 22d1502ae3859b9ac61a95c5477c65423454dd312cb2bf0bc92270ea67769ca32bd8d64645ced86b9115e2ca1f9cc02de0b997b7c9d044d806f598fabfbd7f2e
Binary file
Binary file
@@ -199,6 +199,8 @@ module Phonelib
199
199
  NATIONAL_PREFIX = :national_prefix
200
200
  # @private National prefix for parsing key
201
201
  NATIONAL_PREFIX_FOR_PARSING = :national_prefix_for_parsing
202
+ # @private National prefix transform rule key
203
+ NATIONAL_PREFIX_TRANSFORM_RULE = :national_prefix_transform_rule
202
204
  # @private National prefix rule key
203
205
  NATIONAL_PREFIX_RULE = :national_prefix_formatting_rule
204
206
  # @private Country code key
@@ -78,6 +78,9 @@ module Phonelib
78
78
  country = hash_from_xml(el, :attributes)
79
79
  country.merge! types_and_formats(el.children)
80
80
  country = add_double_country_flag country
81
+ if country[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
82
+ country[Core::NATIONAL_PREFIX_TRANSFORM_RULE].gsub!('$', '\\')
83
+ end
81
84
  @data[country[:id]] = country
82
85
  end
83
86
  end
@@ -91,17 +91,6 @@ module Phonelib
91
91
  "\\d{#{m}}"
92
92
  end
93
93
  end.join('|')
94
- =begin
95
- attributes.map do |k, v|
96
- v.split(',').map do |m|
97
- if m.include? '-'
98
- "\\d{#{m.gsub(/[\[\]]/, '').gsub('-', ',')}}"
99
- else
100
- "\\d{#{m}}"
101
- end
102
- end.join('|')
103
- end.join('|')
104
- =end
105
94
  end
106
95
 
107
96
  # method parses raw data file
@@ -46,6 +46,18 @@ module Phonelib
46
46
  base_result
47
47
  end
48
48
 
49
+ # replacing national prefix to simplified format
50
+ def with_replaced_national_prefix(phone, data)
51
+ return phone unless data[Core::NATIONAL_PREFIX_TRANSFORM_RULE]
52
+ pattern = cr("^(?:#{data[Core::NATIONAL_PREFIX_FOR_PARSING]})")
53
+ match = phone.match pattern
54
+ if match && match.captures.compact.size > 0
55
+ phone.gsub(pattern, data[Core::NATIONAL_PREFIX_TRANSFORM_RULE])
56
+ else
57
+ phone
58
+ end
59
+ end
60
+
49
61
  # trying to parse phone for single country including international prefix
50
62
  # check for provided country
51
63
  #
@@ -60,7 +72,7 @@ module Phonelib
60
72
  # if country was provided and it's a valid country, trying to
61
73
  # create e164 representation of phone number,
62
74
  # kind of normalization for parsing
63
- e164 = convert_to_e164 phone, data
75
+ e164 = convert_to_e164 with_replaced_national_prefix(phone, data), data
64
76
  # if phone starts with international prefix of provided
65
77
  # country try to reanalyze without international prefix for
66
78
  # all countries
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # @private
3
- VERSION = '0.6.19'
3
+ VERSION = '0.6.20'
4
4
  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.6.19
4
+ version: 0.6.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Senderovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-03-04 00:00:00.000000000 Z
11
+ date: 2018-04-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: nokogiri
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '='
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 1.6.0
33
+ version: 1.8.1
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '='
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 1.6.0
40
+ version: 1.8.1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: pry
43
43
  requirement: !ruby/object:Gem::Requirement