f_phone 0.1.11 → 0.1.12

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: 3d040e44a7a35202fc182576847b4f75055d948a697a097c2293394779ccf9f2
4
- data.tar.gz: f42c9713a38eb9665a1e9c303269047b0657369e67823a16b9c23ad80283a47c
3
+ metadata.gz: 8b5cc8b30ed1f959038efc71dab88d14cfd4d746db531752dbefe1ea90d82dd8
4
+ data.tar.gz: fbf704d64628f33624a747f36dd41cbcab4e909ffe992c9f795ac94469d4fae8
5
5
  SHA512:
6
- metadata.gz: ad579cb110c706da2f3b7794325c85d72bab297f01a5a9392c999fddc06c249a7425097d7c7e12d90fe005e3f9753d785f6b1a9d271284d73418a9a6ad3e4630
7
- data.tar.gz: fd12ba7952e6a722899b4defd33448014ecad9a3029bdc80a376ab812129a109a59b246cbeec95dd0e6f7f08dd559ce32b8d1303b35215c2d45d7c21cb2f61a0
6
+ metadata.gz: 9f10d92fbe705e3ce970afdaf78566098694d66554984854a1d22af619dc782aa3a35ac2b95a7923817ca4bae94c30af8274365d5fba1b8101d893cbc593671d
7
+ data.tar.gz: 23613fada40625cbc93d3bfde0a21c562bf3d226641c0ca607639ed75c95808a0cd84d58481eb6f1cd3d7fcffc8900e09bc72d4b80873ee429cf07ac831722b1
data/.gitignore CHANGED
@@ -1,11 +1,13 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
4
  /coverage/
5
- /doc/
5
+ /InstalledFiles
6
6
  /pkg/
7
7
  /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
8
11
  /tmp/
9
-
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/README.md CHANGED
@@ -21,8 +21,42 @@ Or install it yourself as:
21
21
  $ gem install f_phone
22
22
 
23
23
  ## Usage
24
+ ### Validation
25
+ Check if a string is a validate phone number.
26
+
27
+ ```ruby
28
+ FPhone.validate? '+14037089189' # => true
29
+ ```
30
+ ### Normalization
31
+
32
+ Normalize phone number to international format
33
+
34
+ ```ruby
35
+
36
+ FPhone.normalize '+1 (403) 708-9999' # => '+14037089999'
37
+ ```
38
+
39
+ Normalize phone number to vietnam format and global format
40
+ ```ruby
41
+ FPhone.format '+84978654321' # => '+84 97 8654321'
42
+ FPhone.format '+84978654321', format: 'global' # => '+84 97 8654321'
43
+ FPhone.format '+84978654321', format: 'vietnam' # => '097 8654321'
44
+
45
+ ```
46
+ Extract country code and country name from number
47
+
48
+ ```ruby
49
+ FPhone.country_code_from_number '+84905634668' # => 'Country code is: 84', 'Viet Nam'
50
+ FPhone.country_code_from_number '+1 (403) 708-9999' # => 'Country code is: 1', 'Canada'
51
+ ```
52
+
53
+ Check phone provider
54
+
55
+ ```ruby
56
+ FPhone.phone_to_provider '0905718768' # => 'Mobifone'
57
+ FPhone.phone_to_provider '0986718768' # => 'Viettel'
58
+ ```
24
59
 
25
- TODO: Write usage instructions here
26
60
 
27
61
  ## Development
28
62
 
@@ -50,6 +50,11 @@ module FPhone
50
50
  "Other"
51
51
  end
52
52
 
53
+ def self.vn_phone?(phone)
54
+ return false unless /\A(\+84|84|084|0)(\d{8}|\d{9})$/.match phone
55
+ true
56
+ end
57
+
53
58
  def self.validate? phone
54
59
  return false if phone.nil?
55
60
  pattern = /^\s*(?:\+?(\d{1,3}))?([-. (]*(\d{3})[-. )]*)?((\d{3})[-. ]*(\d{2,4})(?:[-.x ]*(\d+))?)\s*$/ #reference code at https://regexr.com/38pvb
@@ -66,7 +71,6 @@ module FPhone
66
71
 
67
72
  def self.format phone, options = {}
68
73
  return nil if phone.nil?
69
-
70
74
  phone = phone.gsub(/\D/, "") # Delete any thing other than digits (xoa bat cu thu gi ngoai so)
71
75
  format = options[:format] || "global" # Set default format is global
72
76
  formatted_phone = format == "global" ? self.global_format(phone) : self.national_format(phone)
@@ -1,3 +1,3 @@
1
1
  module FPhone
2
- VERSION = "0.1.11"
2
+ VERSION = "0.1.12"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: f_phone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nguyen Van Thuan
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-12-30 00:00:00.000000000 Z
11
+ date: 2019-12-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: "Used to validate phone numbers, format phone numbers according to international
14
14
  standards or Vietnamese standards, \n extract the country