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 +4 -4
- data/.gitignore +7 -5
- data/README.md +35 -1
- data/lib/f_phone.rb +5 -1
- data/lib/f_phone/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8b5cc8b30ed1f959038efc71dab88d14cfd4d746db531752dbefe1ea90d82dd8
|
|
4
|
+
data.tar.gz: fbf704d64628f33624a747f36dd41cbcab4e909ffe992c9f795ac94469d4fae8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9f10d92fbe705e3ce970afdaf78566098694d66554984854a1d22af619dc782aa3a35ac2b95a7923817ca4bae94c30af8274365d5fba1b8101d893cbc593671d
|
|
7
|
+
data.tar.gz: 23613fada40625cbc93d3bfde0a21c562bf3d226641c0ca607639ed75c95808a0cd84d58481eb6f1cd3d7fcffc8900e09bc72d4b80873ee429cf07ac831722b1
|
data/.gitignore
CHANGED
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
|
|
data/lib/f_phone.rb
CHANGED
|
@@ -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)
|
data/lib/f_phone/version.rb
CHANGED
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.
|
|
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-
|
|
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
|