Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 98 lines (88 sloc) 3.478 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 #
18 # Note: See country_codes.rb for a complete mapping.
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__
a84d745 @floere + DSL rewrite
authored
37 require File.expand_path '../phony/country_definitions', __FILE__
03dc48d @floere - old code (80% replaced), + preparation for new features
authored
38
cedc4c2 @floere + phony rename
authored
39 module Phony
38d6a14 @floere + germany
authored
40
98cc263 @floere + vanity, normalize
authored
41 # Phony uses a single country codes instance.
42 #
43eed69 @floere + DSL rewrite almost finished
authored
43 @codes = CountryCodes.instance
ebaa3a2 @floere + rewrite, split finished
authored
44
45 # Normalizes the given number.
46 #
47 # Useful before inserting the number into a database.
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
48 #
ebaa3a2 @floere + rewrite, split finished
authored
49 def self.normalize phone_number
40d86c8 @floere + bang methods, + docs, + specs
authored
50 normalize! phone_number.dup
51 end
52 def self.normalize! phone_number
53 @codes.normalize phone_number
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
54 end
1b0c34f @floere + massive rewrite, needs cleanup
authored
55
ebaa3a2 @floere + rewrite, split finished
authored
56 # Splits the phone number into pieces according to the country codes.
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
57 #
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
58 def self.split phone_number
40d86c8 @floere + bang methods, + docs, + specs
authored
59 split! phone_number.dup
60 end
61 def self.split! phone_number
62 @codes.split phone_number
31085d7 @floere + README, + gem, + Rakefile, + gemspec, + setup
authored
63 end
1b0c34f @floere + massive rewrite, needs cleanup
authored
64
e650d67 @floere + let's not be too enthusiastic
authored
65 # Formats a E164 number according to local customs.
9c05e49 @floere + US, France, Switzerland, New Zealand,...
authored
66 #
ebaa3a2 @floere + rewrite, split finished
authored
67 def self.formatted phone_number, options = {}
b742c4f @floere + cleanup
authored
68 formatted! phone_number.dup, options
3e8fd89 @floere + normalizing numbers
authored
69 end
b742c4f @floere + cleanup
authored
70 def self.formatted! phone_number, options = {}
40d86c8 @floere + bang methods, + docs, + specs
authored
71 @codes.formatted phone_number, options
72 end
73
525e5f5 @floere + vanity number handling
authored
74 # def self.service? number
75 # @codes.service? number.dup
76 # end
77 # def self.mobile? number
78 # @codes.mobile? number.dup
79 # end
80 # def self.landline? number
81 # @codes.landline? number.dup
82 # end
b742c4f @floere + cleanup
authored
83
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
84 # Returns true if there is a character in the number
85 # after the first four numbers.
eaad76e @andi + vanity_number handling
andi authored
86 #
660a0c3 @floere + total rewrite of phony. Faster, more readable, easier expandable
authored
87 def self.vanity? phone_number
98cc263 @floere + vanity, normalize
authored
88 @codes.vanity? phone_number.dup
eaad76e @andi + vanity_number handling
andi authored
89 end
90
ebaa3a2 @floere + rewrite, split finished
authored
91 # Converts any character in the vanity_number to its numeric representation.
eaad76e @andi + vanity_number handling
andi authored
92 # Does not check if the passed number is a valid vanity_number, simply does replacement.
93 #
147134d @floere + vanity number rewrite
authored
94 def self.vanity_to_number vanity_number
98cc263 @floere + vanity, normalize
authored
95 @codes.vanity_to_number vanity_number.dup
eaad76e @andi + vanity_number handling
andi authored
96 end
97
c8c60f8 @floere + e164 basics
authored
98 end
Something went wrong with that request. Please try again.