phonelib 0.6.9 → 0.6.10

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: 057bf64ada014da3a08f3355708b52ff368ecbba
4
- data.tar.gz: 58f4e1fd554667c03f827fc73b45fdcb91c38cfe
3
+ metadata.gz: 9c2862f5e9f97af025f8a5beba5a99c68fa24a85
4
+ data.tar.gz: e1d12a6507f085b7c1ee633e8940cf88dbdd1dab
5
5
  SHA512:
6
- metadata.gz: e7dc5128f57dd6d743d32ea86ae5de72cf3ac539d19a3bafa7fc8d33153520d7382d786286e417be9b4fb31f0cf69b9e5baa4c353de51d68754397862db28bb5
7
- data.tar.gz: 4abda9ec008548813bd838137a4f9139345f57f2e794f296f218db0d48263c14874446aac396f1d264e5f864a35294a22aa6b2b6d8b619d5652f0237eb167caa
6
+ metadata.gz: 4e5cb8d9c464042b48411057ff7367bcb5ed5d3893454469dd65ddd96812e5ada4048883c4eaa49dc8a5d0927125e9ee40b7c9ccc484121c67489b0427858b2b
7
+ data.tar.gz: e0541b7cf75c20d71a65297263bfa06b6941a6afffd9375aed0968df040e2bb6f2642e650b4535faf15fc54c0c5827ca3957c525c47ee0197eb10877aff6ab03
data/README.md CHANGED
@@ -50,6 +50,12 @@ To use the ability to parse special numbers (Short Codes, Emergency etc.) you ca
50
50
  Phonelib.parse_special = true
51
51
  ```
52
52
 
53
+ To allow vanity phone numbers conversion you can set ```Phonelib.vanity_conversion``` to ```true```. This will convert characters in passed phone number to their numeric representation (800-CALL-NOW will be 800-225-5669).
54
+
55
+ ``` ruby
56
+ Phonelib.vanity_conversion = true
57
+ ```
58
+
53
59
  To disable sanitizing of passed phone number (keeping digits only)
54
60
 
55
61
  ``` ruby
@@ -226,6 +232,12 @@ You can get E164 formatted number
226
232
  phone.e164 # returns number in E164 format
227
233
  ```
228
234
 
235
+ There is a ```to_s``` method, it will return ```e164``` in case number is valid and ```original``` otherwise
236
+
237
+ ``` ruby
238
+ phone.to_s # returns number in E164 format if number is valid or original otherwise
239
+ ```
240
+
229
241
  There is extended data available for numbers. It will return <tt>nil</tt> in case there is no data or phone is impossible.
230
242
  Can return array of values in case there are some results for specified number
231
243
 
Binary file
Binary file
@@ -117,6 +117,16 @@ module Phonelib
117
117
  @@override_phone_data
118
118
  end
119
119
 
120
+ @@vanity_conversion = false
121
+ # setter for vanity phone numbers chars replacement
122
+ def vanity_conversion=(value)
123
+ @@vanity_conversion = value
124
+ end
125
+
126
+ def vanity_conversion
127
+ @@vanity_conversion
128
+ end
129
+
120
130
  # gem constants definition
121
131
 
122
132
  # @private Main data file
@@ -18,7 +18,7 @@ module Phonelib
18
18
  include Phonelib::DataImporterHelper
19
19
 
20
20
  # countries that can have double country prefix in number
21
- DOUBLE_COUNTRY_CODES_COUNTRIES = %w(IN DE BR IT)
21
+ DOUBLE_COUNTRY_CODES_COUNTRIES = %w(IN DE BR IT NO)
22
22
 
23
23
  # main data file in repo
24
24
  MAIN_FILE = 'resources/PhoneNumberMetadata.xml'
@@ -32,14 +32,18 @@ module Phonelib
32
32
  end
33
33
  end
34
34
 
35
+ # method returns string representation of parsed phone
36
+ def to_s
37
+ valid? ? e164 : original
38
+ end
39
+
35
40
  # method to get sanitized phone number (only numbers)
36
41
  # @return [String] Sanitized phone number
37
42
  def sanitized
38
- @sanitized = if Phonelib.strict_check
39
- @original && @original.gsub(/^\+/, '') || ''
40
- else
41
- @original && @original.gsub(/[^0-9]+/, '') || ''
42
- end
43
+ @sanitized ||=
44
+ vanity_converted(@original).gsub(
45
+ Phonelib.strict_check ? /^\+/.freeze : /[^0-9]+/.freeze,
46
+ '')
43
47
  end
44
48
 
45
49
  # Returns all phone types that matched valid patterns
@@ -3,6 +3,20 @@ module Phonelib
3
3
  module PhoneAnalyzerHelper
4
4
  private
5
5
 
6
+ def vanity_converted(phone)
7
+ return phone unless Phonelib.vanity_conversion
8
+
9
+ (phone || '').gsub(/[a-z]/i.freeze) do |c|
10
+ c.upcase!
11
+ # subtract "A"
12
+ n = (c.ord - 65) / 3
13
+ # account for #7 & #9 which have 4 chars
14
+ n -= 1 if c == 'S'.freeze || c == 'V'.freeze || c >= 'Y'.freeze
15
+ (n + 2).to_s
16
+ end
17
+ end
18
+
19
+
6
20
  # defines if to validate against single country or not
7
21
  def passed_country(country)
8
22
  code = country_prefix(country)
@@ -45,6 +45,7 @@ module Phonelib
45
45
  return nil unless ext_data[id_key] > 0
46
46
 
47
47
  res = Phonelib.phone_ext_data[names_key][ext_data[id_key]]
48
+ return nil unless res
48
49
  res.size == 1 ? res.first : res
49
50
  end
50
51
 
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # @private
3
- VERSION = '0.6.9'
3
+ VERSION = '0.6.10'
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.9
4
+ version: 0.6.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Senderovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-18 00:00:00.000000000 Z
11
+ date: 2017-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -152,11 +152,7 @@ homepage: https://github.com/daddyz/phonelib
152
152
  licenses:
153
153
  - MIT
154
154
  metadata: {}
155
- post_install_message: |2
156
- IMPORTANT NOTICE!
157
- Phone types were changed from camel case to snake case!
158
- Example: ":tollFree" changed to ":toll_free".
159
- Please update your app in case you are checking types!
155
+ post_install_message:
160
156
  rdoc_options:
161
157
  - " --no-private - CHANGELOG.md --readme README.md"
162
158
  require_paths: