kontact 0.1.0 → 0.3.0
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/lib/kontact/brazil.rb +17 -0
- data/lib/kontact/usa.rb +13 -0
- data/lib/kontact/version.rb +1 -1
- data/lib/kontact.rb +13 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e91aa3dabbe1b5d91b218fdd45af03bd5943a7eb4ecc513e8968f83e2a9984de
|
4
|
+
data.tar.gz: b12de2a9620ae21aaee794eb246b19396638929981180b7a3cb282fc7003acf9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f50ce9876333d91770e612eb15ad733bb2c101a319e152baf884c5e34501932d347b6a01099170bdc31530662d81039419ce8af02a25ca34a012ebbfe52ecde4
|
7
|
+
data.tar.gz: c7785552eb817ede09affddc7c1c697c019371d5bd7cc19ef848d3b76fb6a1e3e36e5e56bcddb6116dc2ff6b9062061b7cf77f95fa272bce1641773b7f9e9323
|
data/lib/kontact/brazil.rb
CHANGED
@@ -29,5 +29,22 @@ module Kontact
|
|
29
29
|
end
|
30
30
|
"+55 #{ddd} #{number}"
|
31
31
|
end
|
32
|
+
|
33
|
+
def self.valid?(number)
|
34
|
+
match = number.match(/\A\+55 (\d{2}) (\d{4,5})-(\d{4})\z/)
|
35
|
+
return false unless match
|
36
|
+
|
37
|
+
ddd = match[1]
|
38
|
+
prefix = match[2]
|
39
|
+
return false unless DDDs.include?(ddd)
|
40
|
+
|
41
|
+
if prefix.length == 5
|
42
|
+
prefix.start_with?("9")
|
43
|
+
elsif prefix.length == 4
|
44
|
+
prefix[0].to_i.between?(2, 5)
|
45
|
+
else
|
46
|
+
false
|
47
|
+
end
|
48
|
+
end
|
32
49
|
end
|
33
50
|
end
|
data/lib/kontact/usa.rb
CHANGED
@@ -59,5 +59,18 @@ module Kontact
|
|
59
59
|
return prefix unless [911, 411, 555].include?(prefix)
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
def self.valid?(number)
|
64
|
+
match = number.match(/\A\+1 (\d{3}) (\d{3})-(\d{4})\z/)
|
65
|
+
return false unless match
|
66
|
+
|
67
|
+
area = match[1]
|
68
|
+
prefix = match[2].to_i
|
69
|
+
return false unless AREAS.include?(area)
|
70
|
+
return false if [911, 411, 555].include?(prefix)
|
71
|
+
return false unless prefix.to_s[0].match?(/[2-9]/)
|
72
|
+
|
73
|
+
true
|
74
|
+
end
|
62
75
|
end
|
63
76
|
end
|
data/lib/kontact/version.rb
CHANGED
data/lib/kontact.rb
CHANGED
@@ -13,4 +13,17 @@ module Kontact
|
|
13
13
|
raise ArgumentError, "Unsupported country: #{country}"
|
14
14
|
end
|
15
15
|
end
|
16
|
+
|
17
|
+
def self.valid?(number, country)
|
18
|
+
raise ArgumentError, "Number can not empty or blank" unless number
|
19
|
+
|
20
|
+
case country.to_sym
|
21
|
+
when :brazil
|
22
|
+
Brazil.valid?(number)
|
23
|
+
when :usa
|
24
|
+
USA.valid?(number)
|
25
|
+
else
|
26
|
+
raise ArgumentError, "Unsupported country: #{country}"
|
27
|
+
end
|
28
|
+
end
|
16
29
|
end
|