Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 118 lines (104 sloc) 4.026 kB
cedc4c2 @floere + phony rename
authored
1 # Framework.
2 #
147134d @floere + vanity number rewrite
authored
3 require File.expand_path '../phony/vanity', __FILE__
fc827a4 @floere + introduced countries without area code, + regexp formatter
authored
4 require File.expand_path '../phony/local_splitters/fixed', __FILE__
5 require File.expand_path '../phony/local_splitters/regex', __FILE__
a84d745 @floere + DSL rewrite
authored
6 require File.expand_path '../phony/national_splitters/dsl', __FILE__
e0ae1c3 @floere + rename, + first vestiges of service/mobile/landline recognition
authored
7 require File.expand_path '../phony/national_splitters/fixed', __FILE__
8 require File.expand_path '../phony/national_splitters/variable', __FILE__
a84d745 @floere + DSL rewrite
authored
9 require File.expand_path '../phony/national_splitters/regex', __FILE__
fc827a4 @floere + introduced countries without area code, + regexp formatter
authored
10 require File.expand_path '../phony/national_splitters/none', __FILE__
3851473 @mrchucho Allow unsupported countries to use a more conservative default.
mrchucho authored
11 require File.expand_path '../phony/national_splitters/default', __FILE__
ebaa3a2 @floere + rewrite, split finished
authored
12 require File.expand_path '../phony/national_code', __FILE__
40e77a8 @floere + intermediate commit
authored
13 require File.expand_path '../phony/country', __FILE__
43eed69 @floere + DSL rewrite almost finished
authored
14 require File.expand_path '../phony/country_codes', __FILE__
3bbddb8 @floere + experimental 1.6.6 release of plausibility checking
authored
15 require File.expand_path '../phony/validator', __FILE__
16 require File.expand_path '../phony/validators', __FILE__
a84d745 @floere + DSL rewrite
authored
17 require File.expand_path '../phony/dsl', __FILE__
18
98cc263 @floere + vanity, normalize
authored
19 # Countries.
ebaa3a2 @floere + rewrite, split finished
authored
20 #
b136423 @floere + countries definitions extracted, + regex
authored
21 # The ones that need more space to define.
cedc4c2 @floere + phony rename
authored
22 #
ebaa3a2 @floere + rewrite, split finished
authored
23 require File.expand_path '../phony/countries/austria', __FILE__
885869c @floere + Ni hao, China.
authored
24 require File.expand_path '../phony/countries/china', __FILE__
ebaa3a2 @floere + rewrite, split finished
authored
25 require File.expand_path '../phony/countries/germany', __FILE__
b58b2c3 @stevenyan Adds support for Republic of Ireland phone number formatting
stevenyan authored
26 require File.expand_path '../phony/countries/ireland', __FILE__
9b37d4c @floere + italian phone numbers
authored
27 require File.expand_path '../phony/countries/italy', __FILE__
0fb354a @floere + 1.2.4, Malaysia
authored
28 require File.expand_path '../phony/countries/malaysia', __FILE__
f01d580 @floere + first draft for the netherlands
authored
29 require File.expand_path '../phony/countries/netherlands', __FILE__
5fd6965 @floere + Annyeonhaseyo, South Korea!
authored
30 require File.expand_path '../phony/countries/south_korea', __FILE__
da33c53 @floere + sweden, yay, + russia, sweden specs
authored
31 require File.expand_path '../phony/countries/sweden', __FILE__
c8173d5 @kbingman added uk
kbingman authored
32 require File.expand_path '../phony/countries/united_kingdom', __FILE__
b136423 @floere + countries definitions extracted, + regex
authored
33 #
34 # All other countries.
35 #
b6cbfbb @floere + moved countries.rb inside phony (thanks trans!)
authored
36 require File.expand_path '../phony/countries', __FILE__
03dc48d @floere - old code (80% replaced), + preparation for new features
authored
37
cedc4c2 @floere + phony rename
authored
38 module Phony
47d4092 @floere + Big DSL rewrite
authored
39
98cc263 @floere + vanity, normalize
authored
40 # Phony uses a single country codes instance.
41 #
f1dfaef @floere + 1.6.7, improved experimental validation
authored
42 @codes = CountryCodes.instance
43 @validators = Validators.instance
47d4092 @floere + Big DSL rewrite
authored
44
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
45 class << self
47d4092 @floere + Big DSL rewrite
authored
46
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
47 # Normalizes the given number.
48 #
49 # Useful before inserting the number into a database.
50 #
51 def normalize phone_number
c05b476 @floere + 1.5.0, + cleanly raise on nil number in interface methods
authored
52 raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.normalize(number)." unless phone_number
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
53 normalize! phone_number.dup
54 end
55 def normalize! phone_number
56 @codes.normalize phone_number
57 end
47d4092 @floere + Big DSL rewrite
authored
58
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
59 # Splits the phone number into pieces according to the country codes.
60 #
61 def split phone_number
c05b476 @floere + 1.5.0, + cleanly raise on nil number in interface methods
authored
62 raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.split(number)." unless phone_number
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
63 split! phone_number.dup
64 end
65 def split! phone_number
66 @codes.split phone_number
67 end
47d4092 @floere + Big DSL rewrite
authored
68
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
69 # Formats a E164 number according to local customs.
70 #
71 def format phone_number, options = {}
c05b476 @floere + 1.5.0, + cleanly raise on nil number in interface methods
authored
72 raise ArgumentError, "Phone number cannot be nil. Use e.g. number && Phony.format(number)." unless phone_number
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
73 formatted! phone_number.dup, options
74 end
75 def format! phone_number, options = {}
76 @codes.formatted phone_number, options
77 end
78 alias formatted format
79 alias formatted! format!
3bbddb8 @floere + experimental 1.6.6 release of plausibility checking
authored
80
81 # Makes a plausibility check.
82 #
83 # If it returns false, it is not plausible.
84 # If it returns true, it is unclear whether it is plausible,
85 # leaning towards being plausible.
86 #
87 def plausible? number, hints = {}
f1dfaef @floere + 1.6.7, improved experimental validation
authored
88 @validators.plausible? number, hints
3bbddb8 @floere + experimental 1.6.6 release of plausibility checking
authored
89 end
47d4092 @floere + Big DSL rewrite
authored
90
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method …
authored
91 # def service? number
92 # @codes.service? number.dup
93 # end
94 # def mobile? number
95 # @codes.mobile? number.dup
96 # end
97 # def landline? number
98 # @codes.landline? number.dup
99 # end
100
101 # Returns true if there is a character in the number
102 # after the first four numbers.
103 #
104 def vanity? phone_number
105 @codes.vanity? phone_number.dup
106 end
107
108 # Converts any character in the vanity_number to its numeric representation.
109 # Does not check if the passed number is a valid vanity_number, simply does replacement.
110 #
111 def vanity_to_number vanity_number
112 @codes.vanity_to_number vanity_number.dup
113 end
47d4092 @floere + Big DSL rewrite
authored
114
eaad76e @andi + vanity_number handling
andi authored
115 end
47d4092 @floere + Big DSL rewrite
authored
116
3851473 @mrchucho Allow unsupported countries to use a more conservative default.
mrchucho authored
117 end
Something went wrong with that request. Please try again.