Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 101 lines (88 sloc) 3.159 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__
a84d745 @floere + DSL rewrite
authored
15 require File.expand_path '../phony/dsl', __FILE__
16
98cc263 @floere + vanity, normalize
authored
17 # Countries.
ebaa3a2 @floere + rewrite, split finished
authored
18 #
b136423 @floere + countries definitions extracted, + regex
authored
19 # The ones that need more space to define.
cedc4c2 @floere + phony rename
authored
20 #
ebaa3a2 @floere + rewrite, split finished
authored
21 require File.expand_path '../phony/countries/austria', __FILE__
885869c @floere + Ni hao, China.
authored
22 require File.expand_path '../phony/countries/china', __FILE__
ebaa3a2 @floere + rewrite, split finished
authored
23 require File.expand_path '../phony/countries/germany', __FILE__
9b37d4c @floere + italian phone numbers
authored
24 require File.expand_path '../phony/countries/italy', __FILE__
0fb354a @floere + 1.2.4, Malaysia
authored
25 require File.expand_path '../phony/countries/malaysia', __FILE__
f01d580 @floere + first draft for the netherlands
authored
26 require File.expand_path '../phony/countries/netherlands', __FILE__
5fd6965 @floere + Annyeonhaseyo, South Korea!
authored
27 require File.expand_path '../phony/countries/south_korea', __FILE__
da33c53 @floere + sweden, yay, + russia, sweden specs
authored
28 require File.expand_path '../phony/countries/sweden', __FILE__
c8173d5 @kbingman added uk
kbingman authored
29 require File.expand_path '../phony/countries/united_kingdom', __FILE__
b136423 @floere + countries definitions extracted, + regex
authored
30 #
31 # All other countries.
32 #
b6cbfbb @floere + moved countries.rb inside phony (thanks trans!)
authored
33 require File.expand_path '../phony/countries', __FILE__
03dc48d @floere - old code (80% replaced), + preparation for new features
authored
34
cedc4c2 @floere + phony rename
authored
35 module Phony
47d4092 @floere + Big DSL rewrite
authored
36
98cc263 @floere + vanity, normalize
authored
37 # Phony uses a single country codes instance.
38 #
43eed69 @floere + DSL rewrite almost finished
authored
39 @codes = CountryCodes.instance
47d4092 @floere + Big DSL rewrite
authored
40
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method sti...
authored
41 class << self
47d4092 @floere + Big DSL rewrite
authored
42
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method sti...
authored
43 # Normalizes the given number.
44 #
45 # Useful before inserting the number into a database.
46 #
47 def normalize phone_number
48 normalize! phone_number.dup
49 end
50 def normalize! phone_number
51 @codes.normalize phone_number
52 end
47d4092 @floere + Big DSL rewrite
authored
53
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method sti...
authored
54 # Splits the phone number into pieces according to the country codes.
55 #
56 def split phone_number
57 split! phone_number.dup
58 end
59 def split! phone_number
60 @codes.split phone_number
61 end
47d4092 @floere + Big DSL rewrite
authored
62
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method sti...
authored
63 # Formats a E164 number according to local customs.
64 #
65 def format phone_number, options = {}
66 formatted! phone_number.dup, options
67 end
68 def format! phone_number, options = {}
69 @codes.formatted phone_number, options
70 end
71 alias formatted format
72 alias formatted! format!
47d4092 @floere + Big DSL rewrite
authored
73
24c56de @floere + Version 1.4.0. Changed Phony.formatted to Phony.format. Old method sti...
authored
74 # def service? number
75 # @codes.service? number.dup
76 # end
77 # def mobile? number
78 # @codes.mobile? number.dup
79 # end
80 # def landline? number
81 # @codes.landline? number.dup
82 # end
83
84 # Returns true if there is a character in the number
85 # after the first four numbers.
86 #
87 def vanity? phone_number
88 @codes.vanity? phone_number.dup
89 end
90
91 # Converts any character in the vanity_number to its numeric representation.
92 # Does not check if the passed number is a valid vanity_number, simply does replacement.
93 #
94 def vanity_to_number vanity_number
95 @codes.vanity_to_number vanity_number.dup
96 end
47d4092 @floere + Big DSL rewrite
authored
97
eaad76e @andi + vanity_number handling
andi authored
98 end
47d4092 @floere + Big DSL rewrite
authored
99
3851473 @mrchucho Allow unsupported countries to use a more conservative default.
mrchucho authored
100 end
Something went wrong with that request. Please try again.