-
-
Notifications
You must be signed in to change notification settings - Fork 226
/
phony.rb
94 lines (83 loc) · 3.07 KB
/
phony.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Framework.
#
require File.expand_path '../phony/vanity', __FILE__
require File.expand_path '../phony/local_splitter', __FILE__
require File.expand_path '../phony/national_splitters/fixed', __FILE__
require File.expand_path '../phony/national_splitters/variable', __FILE__
require File.expand_path '../phony/national_code', __FILE__
require File.expand_path '../phony/country', __FILE__
# Countries.
#
# Note: See country_codes.rb for a complete mapping.
#
require File.expand_path '../phony/countries/all_other', __FILE__
require File.expand_path '../phony/countries/austria', __FILE__
require File.expand_path '../phony/countries/belgium', __FILE__
require File.expand_path '../phony/countries/chile', __FILE__
require File.expand_path '../phony/countries/china', __FILE__
require File.expand_path '../phony/countries/egypt', __FILE__
require File.expand_path '../phony/countries/germany', __FILE__
require File.expand_path '../phony/countries/greece', __FILE__
require File.expand_path '../phony/countries/hungary', __FILE__
require File.expand_path '../phony/countries/italy', __FILE__
require File.expand_path '../phony/countries/malaysia', __FILE__
require File.expand_path '../phony/countries/netherlands', __FILE__
require File.expand_path '../phony/countries/peru', __FILE__
require File.expand_path '../phony/countries/portugal', __FILE__
require File.expand_path '../phony/countries/romania', __FILE__
require File.expand_path '../phony/countries/south_korea', __FILE__
require File.expand_path '../phony/countries/sweden', __FILE__
require File.expand_path '../phony/countries/united_kingdom', __FILE__
require File.expand_path '../phony/country_codes', __FILE__
module Phony
# Phony uses a single country codes instance.
#
@codes = CountryCodes.new
# Normalizes the given number.
#
# Useful before inserting the number into a database.
#
def self.normalize phone_number
normalize! phone_number.dup
end
def self.normalize! phone_number
@codes.normalize phone_number
end
# Splits the phone number into pieces according to the country codes.
#
def self.split phone_number
split! phone_number.dup
end
def self.split! phone_number
@codes.split phone_number
end
# Formats a E164 number according to local customs.
#
def self.formatted phone_number, options = {}
formatted! phone_number.dup, options
end
def self.formatted! phone_number, options = {}
@codes.formatted phone_number, options
end
# def self.service? number
# @codes.service? number.dup
# end
# def self.mobile? number
# @codes.mobile? number.dup
# end
# def self.landline? number
# @codes.landline? number.dup
# end
# Returns true if there is a character in the number
# after the first four numbers.
#
def self.vanity? phone_number
@codes.vanity? phone_number.dup
end
# Converts any character in the vanity_number to its numeric representation.
# Does not check if the passed number is a valid vanity_number, simply does replacement.
#
def self.vanity_to_number vanity_number
@codes.vanity_to_number vanity_number.dup
end
end