phonelib 0.6.30 → 0.6.31

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: ed67690c6b06bf398a88577a276e5cac93aeef6e
4
- data.tar.gz: 556aea07788ad0857044e7caf02b6b87b2f2733d
3
+ metadata.gz: 43546d3902acfd547a1f87e50e537819435332f6
4
+ data.tar.gz: bf66b6bf8704ac1cfe8634073abea9b4952f3ab7
5
5
  SHA512:
6
- metadata.gz: de1c6fdcc910e403e487d1fe02dab34cb499603ab838cda685256669b490837526f95b296502ea0104c5bfd8431fe9930fb406f99c4e58e7d0b20ee3087dfa5d
7
- data.tar.gz: 5fcd25ec954a4906c9ef5e5b200f2244ee0ae1a4d7b4f77f67bb086742c52f619eef1b3aa687b896d7cdce5dfe6eeb003ca3ad5c19e0092aac3d029eb535222d
6
+ metadata.gz: 7b7b9bfae6444b5024a1777cfeee308698460017d8d49f540b3da544ebec9c9631a21f988f7db9c8f574ca2170a160646763a25a323e8f1d1b5151c99d54347f
7
+ data.tar.gz: de56a607d4e6d5e077014a9377978cb36055b2d789f94fb65673be7aae8b33a50c9f5dcaabf313b5a7d9150c0ea8c71d1cb993dc2a594997fd35ab1ac16cf96f
data/README.md CHANGED
@@ -238,6 +238,17 @@ You can get E164 formatted number
238
238
  phone.e164 # returns number in E164 format
239
239
  ```
240
240
 
241
+ You can define prefix for ```international``` and ```e164``` related methods to get formatted number prefixed with anything you need.
242
+
243
+ ``` ruby
244
+ phone.international('00') # returns formatted international number prefixed by 00 instead of +
245
+ phone.e164('00') # returns e164 represantation of a number prefixed by 00 instead of +
246
+ phone.full_international('00') # returns formatted international number with extension prefixed by 00 instead of +
247
+ phone.full_e164('00') # returns e164 represantation of a number with extension prefixed by 00 instead of +
248
+ phone.international_00 # same as phone.international('00'). 00 can be replaced with whatever you need
249
+ phone.e164_00 # same as phone.international('00')
250
+ ```
251
+
241
252
  There is a ```to_s``` method, it will return ```e164``` in case number is valid and ```original``` otherwise
242
253
 
243
254
  ``` ruby
Binary file
Binary file
@@ -36,12 +36,14 @@ module Phonelib
36
36
  Phonelib.phone_data[country][Core::COUNTRY_CODE]
37
37
  end
38
38
 
39
- # Returns e164 formatted phone number
39
+ # Returns e164 formatted phone number. Method can receive single string parameter that will be defined as prefix
40
40
  # @param formatted [Boolean] whether to return numbers only or formatted
41
+ # @param prefix [String] prefix to be placed before the number, "+" by default
41
42
  # @return [String] formatted international number
42
- def international(formatted = true)
43
+ def international(formatted = true, prefix = '+')
44
+ prefix = formatted if formatted.is_a?(String)
43
45
  return nil if sanitized.empty?
44
- return "+#{country_prefix_or_not}#{sanitized}" unless valid?
46
+ return "#{prefix}#{country_prefix_or_not}#{sanitized}" unless valid?
45
47
  return country_code + @national_number unless formatted
46
48
 
47
49
  fmt = @data[country][:format]
@@ -51,7 +53,7 @@ module Phonelib
51
53
  national = fmt.gsub(/\$\d/) { |el| matches[el[1].to_i] }
52
54
  end
53
55
 
54
- "+#{country_code} #{national}"
56
+ "#{prefix}#{country_code} #{national}"
55
57
  end
56
58
 
57
59
  # returns national formatted number with extension added
@@ -61,22 +63,25 @@ module Phonelib
61
63
  end
62
64
 
63
65
  # returns international formatted number with extension added
66
+ # @param prefix [String] prefix to be placed before the number, "+" by default
64
67
  # @return [String] formatted internation phone number with extension
65
- def full_international
66
- "#{international}#{formatted_extension}"
68
+ def full_international(prefix = '+')
69
+ "#{international(true, prefix)}#{formatted_extension}"
67
70
  end
68
71
 
69
72
  # returns e164 format of phone with extension added
73
+ # @param prefix [String] prefix to be placed before the number, "+" by default
70
74
  # @return [String] phone formatted in E164 format with extension
71
- def full_e164
72
- "#{e164}#{formatted_extension}"
75
+ def full_e164(prefix = '+')
76
+ "#{e164(prefix)}#{formatted_extension}"
73
77
  end
74
78
 
75
79
  # Returns e164 unformatted phone number
80
+ # @param prefix [String] prefix to be placed before the number, "+" by default
76
81
  # @return [String] phone formatted in E164 format
77
- def e164
78
- international = self.international
79
- international && international.gsub(/[^+0-9]/, '')
82
+ def e164(prefix = '+')
83
+ international = self.international(false, '')
84
+ international && "#{prefix}#{international}"
80
85
  end
81
86
 
82
87
  # returns area code of parsed number
@@ -93,6 +98,15 @@ module Phonelib
93
98
  format_match[take_group]
94
99
  end
95
100
 
101
+ def method_missing(method, *args)
102
+ prefix_methods = %w(international_ full_international_ e164_ full_e164_)
103
+ method_s = method.to_s
104
+ prefix_methods.each do |key|
105
+ return send(key[0..-2], method_s.gsub(key, '')) if method_s.start_with?(key)
106
+ end
107
+ super
108
+ end
109
+
96
110
  private
97
111
 
98
112
  # @private defines if phone can have area code
@@ -1,4 +1,4 @@
1
1
  module Phonelib
2
2
  # @private
3
- VERSION = '0.6.30'
3
+ VERSION = '0.6.31'
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.30
4
+ version: 0.6.31
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vadim Senderovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-03-06 00:00:00.000000000 Z
11
+ date: 2019-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake