Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 101 lines (91 sloc) 3.479 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__
ebaa3a2 @floere + rewrite, split finished
authored
11 require File.expand_path '../phony/national_code', __FILE__
40e77a8 @floere + intermediate commit
authored
12 require File.expand_path '../phony/country', __FILE__
43eed69 @floere + DSL rewrite almost finished
authored
13 require File.expand_path '../phony/country_codes', __FILE__
a84d745 @floere + DSL rewrite
authored
14 require File.expand_path '../phony/dsl', __FILE__
15
98cc263 @floere + vanity, normalize
authored
16 # Countries.
ebaa3a2 @floere + rewrite, split finished
authored
17 #
b136423 @floere + countries definitions extracted, + regex
authored
18 # The ones that need more space to define.
cedc4c2 @floere + phony rename
authored
19 #
a84d745 @floere + DSL rewrite
authored
20 require File.expand_path '../phony/countries', __FILE__
ebaa3a2 @floere + rewrite, split finished
authored
21 require File.expand_path '../phony/countries/austria', __FILE__
1dacbab @kbingman belgian mobile numbers failing
kbingman authored
22 require File.expand_path '../phony/countries/belgium', __FILE__
67a03da @floere + buen día Chile!
authored
23 require File.expand_path '../phony/countries/chile', __FILE__
885869c @floere + Ni hao, China.
authored
24 require File.expand_path '../phony/countries/china', __FILE__
a4db5e8 @floere + egypt
authored
25 require File.expand_path '../phony/countries/egypt', __FILE__
ebaa3a2 @floere + rewrite, split finished
authored
26 require File.expand_path '../phony/countries/germany', __FILE__
29ea6bb @floere + greece
authored
27 require File.expand_path '../phony/countries/greece', __FILE__
7a40c1c @floere + hungarian numbers, swiss specs
authored
28 require File.expand_path '../phony/countries/hungary', __FILE__
9b37d4c @floere + italian phone numbers
authored
29 require File.expand_path '../phony/countries/italy', __FILE__
0fb354a @floere + 1.2.4, Malaysia
authored
30 require File.expand_path '../phony/countries/malaysia', __FILE__
fc827a4 @floere + introduced countries without area code, + regexp formatter
authored
31 require File.expand_path '../phony/countries/norway', __FILE__
f01d580 @floere + first draft for the netherlands
authored
32 require File.expand_path '../phony/countries/netherlands', __FILE__
e32f33e @floere + romania, best effort, + 1.1.3
authored
33 require File.expand_path '../phony/countries/romania', __FILE__
5fd6965 @floere + Annyeonhaseyo, South Korea!
authored
34 require File.expand_path '../phony/countries/south_korea', __FILE__
da33c53 @floere + sweden, yay, + russia, sweden specs
authored
35 require File.expand_path '../phony/countries/sweden', __FILE__
c8173d5 @kbingman added uk
kbingman authored
36 require File.expand_path '../phony/countries/united_kingdom', __FILE__
b136423 @floere + countries definitions extracted, + regex
authored
37 #
38 # All other countries.
39 #
40 require File.expand_path '../countries', __FILE__
03dc48d @floere - old code (80% replaced), + preparation for new features
authored
41
cedc4c2 @floere + phony rename
authored
42 module Phony
38d6a14 @floere + germany
authored
43
98cc263 @floere + vanity, normalize
authored
44 # Phony uses a single country codes instance.
45 #
43eed69 @floere + DSL rewrite almost finished
authored
46 @codes = CountryCodes.instance
ebaa3a2 @floere + rewrite, split finished
authored
47
48 # Normalizes the given number.
49 #
50 # Useful before inserting the number into a database.
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
51 #
ebaa3a2 @floere + rewrite, split finished
authored
52 def self.normalize phone_number
40d86c8 @floere + bang methods, + docs, + specs
authored
53 normalize! phone_number.dup
54 end
55 def self.normalize! phone_number
56 @codes.normalize phone_number
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
57 end
1b0c34f @floere + massive rewrite, needs cleanup
authored
58
ebaa3a2 @floere + rewrite, split finished
authored
59 # Splits the phone number into pieces according to the country codes.
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
60 #
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
61 def self.split phone_number
40d86c8 @floere + bang methods, + docs, + specs
authored
62 split! phone_number.dup
63 end
64 def self.split! phone_number
65 @codes.split phone_number
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
66 end
1b0c34f @floere + massive rewrite, needs cleanup
authored
67
e650d67 @floere + let's not be too enthusiastic
authored
68 # Formats a E164 number according to local customs.
9c05e49 @floere + US, France, Switzerland, New Zealand,...
authored
69 #
ebaa3a2 @floere + rewrite, split finished
authored
70 def self.formatted phone_number, options = {}
b742c4f @floere + cleanup
authored
71 formatted! phone_number.dup, options
3e8fd89 @floere + normalizing numbers
authored
72 end
b742c4f @floere + cleanup
authored
73 def self.formatted! phone_number, options = {}
40d86c8 @floere + bang methods, + docs, + specs
authored
74 @codes.formatted phone_number, options
75 end
76
525e5f5 @floere + vanity number handling
authored
77 # def self.service? number
78 # @codes.service? number.dup
79 # end
80 # def self.mobile? number
81 # @codes.mobile? number.dup
82 # end
83 # def self.landline? number
84 # @codes.landline? number.dup
85 # end
b742c4f @floere + cleanup
authored
86
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
87 # Returns true if there is a character in the number
88 # after the first four numbers.
eaad76e @andi + vanity_number handling
andi authored
89 #
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
90 def self.vanity? phone_number
98cc263 @floere + vanity, normalize
authored
91 @codes.vanity? phone_number.dup
eaad76e @andi + vanity_number handling
andi authored
92 end
93
ebaa3a2 @floere + rewrite, split finished
authored
94 # Converts any character in the vanity_number to its numeric representation.
eaad76e @andi + vanity_number handling
andi authored
95 # Does not check if the passed number is a valid vanity_number, simply does replacement.
96 #
147134d @floere + vanity number rewrite
authored
97 def self.vanity_to_number vanity_number
98cc263 @floere + vanity, normalize
authored
98 @codes.vanity_to_number vanity_number.dup
eaad76e @andi + vanity_number handling
andi authored
99 end
100
c8c60f8 @floere + e164 basics
authored
101 end
Something went wrong with that request. Please try again.