phones 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/phones/parser.rb +13 -5
- data/lib/phones/version.rb +1 -1
- metadata +1 -1
data/lib/phones/parser.rb
CHANGED
@@ -13,6 +13,8 @@
|
|
13
13
|
require 'phones/phone'
|
14
14
|
module Phones
|
15
15
|
class Parser
|
16
|
+
AMURIKA = '1'.freeze
|
17
|
+
COMMIES = '7'.freeze
|
16
18
|
IGNORABLE_CHARACTERS = /[a-zA-Z]|\-|\s|\.|\(|\)|\;|\:|\*|\&|\%|\$|\#|\@|\!/.freeze
|
17
19
|
def self.parse(options)
|
18
20
|
# Let's figure out what the phone number is
|
@@ -44,17 +46,17 @@ module Phones
|
|
44
46
|
private
|
45
47
|
|
46
48
|
def self.try_without_delimiters!
|
47
|
-
raise ArgumentError, "Valid phone numbers are between 5 and 16" if self.number.length > 5 && self.number.length < 16
|
48
49
|
parts = []
|
49
50
|
# Let's find out if there is a country code
|
50
|
-
country_code = "
|
51
|
+
country_code = "+#{AMURIKA}"
|
51
52
|
# It's easiest to tell when it starts with a plus, so let's start with that
|
52
53
|
log "Number: #{self.number}"
|
54
|
+
raise ArgumentError, "Valid phone numbers are between 5 and 16" unless self.number.length > 5 && self.number.length < 16
|
53
55
|
if self.number[0] == "+"
|
54
56
|
# Estados Unidos!
|
55
|
-
if self.number[1] ==
|
57
|
+
if self.number[1] == AMURIKA && self.number.length == "+19252008843".length
|
56
58
|
parts = [self.number[2..4], self.number[5..-1]]
|
57
|
-
# 3 Digit country code?
|
59
|
+
# 3 Digit country code?
|
58
60
|
elsif COUNTRY_CODES.include?(self.number[1..3])
|
59
61
|
log "Three Digit Country Code: #{self.number[1..3]}"
|
60
62
|
country_code = self.number[0..4]
|
@@ -64,6 +66,9 @@ module Phones
|
|
64
66
|
log "Two Digit Country Code: #{self.number[1..2]}"
|
65
67
|
country_code = self.number[0..2]
|
66
68
|
parts = [nil, self.number[4..-1]]
|
69
|
+
elsif self.number[1] == COMMIES
|
70
|
+
country_code = self.number[0..1]
|
71
|
+
parts = [nil, self.number[2..-1]]
|
67
72
|
else
|
68
73
|
# IDK, man
|
69
74
|
raise ArgumentError, "Can't parse phone number"
|
@@ -79,6 +84,9 @@ module Phones
|
|
79
84
|
log "Two Digit Country Code: #{self.number[0..1]}"
|
80
85
|
country_code = "+" + self.number[0..1]
|
81
86
|
parts = [nil, self.number[2..-1]]
|
87
|
+
elsif self.number[1] == COMMIES
|
88
|
+
country_code = self.number[0..1]
|
89
|
+
parts = [nil, self.number[2..-1]]
|
82
90
|
else
|
83
91
|
# IDK, man
|
84
92
|
raise ArgumentError, "Can't parse phone number"
|
@@ -104,6 +112,6 @@ module Phones
|
|
104
112
|
end
|
105
113
|
|
106
114
|
# Source: http://en.wikipedia.org/wiki/List_of_country_calling_codes
|
107
|
-
COUNTRY_CODES = %w(77 20 210 211 212 213 216 218 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 260 261 262 263 264 265 266 267 268 269 27 290 291 297 298 299 30 31 32 33 34 350 351 352 353 354 355 356 357 358 359 36 370 371 372 373 374 375 376 377 378 379 380 381 382 385 386 387 388 389 40 41 420 421 423 43 44 45 46 47 48 49 500 501 502 503 504 505 506 507 508 509 51 52 53 54 55 56 57 58 590 591 592 593 594 595 596 597 598 599 60 61 62 63 64 65 66 670 672 673 674 675 676 677 678 679 680 681 682 683 685 686 687 688 689 690 691 692 800 808 81 82 84 850 852 853 855 856 86 870 878 880 881 882 883 886 888 90 91 92 93 94 95 960 961 962 963 964 965 966 967 968 970 971 972 973 974 975 976 977 979 98 991 992 993 994 995 996 998).freeze
|
115
|
+
COUNTRY_CODES = %w(77 20 210 211 212 213 216 218 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 260 261 262 263 264 265 266 267 268 269 27 290 291 297 298 299 30 31 32 33 34 350 351 352 353 354 355 356 357 358 359 36 370 371 372 373 374 375 376 377 378 379 380 381 382 385 386 387 388 389 40 41 420 421 423 43 44 45 46 47 48 49 500 501 502 503 504 505 506 507 508 509 51 52 53 54 55 56 57 58 590 591 592 593 594 595 596 597 598 599 60 61 62 63 64 65 66 670 672 673 674 675 676 677 678 679 680 681 682 683 685 686 687 688 689 690 691 692 800 808 81 82 84 850 852 853 855 856 86 870 878 880 881 882 883 886 888 90 91 92 93 94 95 960 961 962 963 964 965 966 967 968 970 971 972 973 974 975 976 977 979 98 991 992 993 994 995 996 998 7).freeze
|
108
116
|
end
|
109
117
|
end
|
data/lib/phones/version.rb
CHANGED