Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 163 lines (84 sloc) 6.845 kB
cedc4c2 @floere + phony rename
authored
1 h1. Phony
f3ed13c @floere + README improved
authored
2
7710d81 @floere + travis status light
authored
3 "!https://secure.travis-ci.org/floere/phony.png!":http://travis-ci.org/floere/phony
4
bd11c99 @floere + zendesk
authored
5 Used in e.g.: "airbnb.com":http://airbnb.com, "restorm.com":http://restorm.com, "socialcam.com":http://socialcam.com, "zendesk.com":http://www.zendesk.com/ (and many, many others).
c87d725 @floere + users
authored
6
b58001c @floere + US spec
authored
7 There's also a Rails wrapper: https://github.com/joost/phony_rails.
8
f3ed13c @floere + README improved
authored
9 h2. Description
10
e650d67 @floere + let's not be too enthusiastic
authored
11 This gem can normalize, format and split E164 numbers.
3a26fcc @floere + E164 link in README
authored
12 "More about E164 numbers in this Wiki":http://en.wikipedia.org/wiki/E.164.
f3ed13c @floere + README improved
authored
13
a17a5ab @floere + goal in README
authored
14 The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
15
68f2603 @floere ! README
authored
16 Currently handles Afghan, Algerian, Austrian, Australian, Belgian, Brazilian, Chilean, Chinese, Croatian, Cuban, Czech, Danish, Dutch, Egyptian, French, German, Ghanan, Greek, Hungarian, Italian, Irish, Lithuanian, Malaysian, Mexican, New Zealand, Norwegian, Peruvian, Polish, Russian, Romanian, Singapore, Slovakian, South African, South Korean, Spanish, Swedish, Swiss, Thailand, Tunisian, Turkish, Liechtenstein, UK, US, Venezuelan, and Vietnamese numbers.
4712a10 @floere ! typo
authored
17 And to some extent, all others. Just try if it works for you.
03dc48d @floere - old code (80% replaced), + preparation for new features
authored
18
03555a3 @floere + Countries list
authored
19 If it doesn't, please "enter an issue":http://github.com/floere/phony/issues.
20
b18da2a @floere + installation in readme
authored
21 h2. Installation
22
3a26fcc @floere + E164 link in README
authored
23 <pre><code>gem install phony</code></pre>
b18da2a @floere + installation in readme
authored
24
b58001c @floere + US spec
authored
25 h2(#examples). Some examples
f3ed13c @floere + README improved
authored
26
e0b473e @floere + anchors
authored
27 h3(#plausibility). Plausibility
66bc80a @floere + updated README with information on #plausible?
authored
28
29 "Plausible" means "seems reasonable or probable", not implying 100% correctness on a @true@, but implying 100% correctness on a @false@ return value. So if this returns @true@, it might still be not a plausible number. If it returns @false@, it is definitely not an E164 conform number.
30
31 Use this method in combination with @normalize@ for saving it into the database. Also see https://github.com/floere/phony/issues/35 for a discussion on the topic.
32
b868451 @floere + notes on plausible?
authored
33 Note that you can add constraints to the plausibility check like the country code, @cc@, and the national destination code, @ndc@. Use the options to further limit the plausibility range. For example, only allow a small number of countries.
34
66bc80a @floere + updated README with information on #plausible?
authored
35 @Phony.plausible?('0000000').should be_false@
36
37 @Phony.plausible?('hello').should be_false@
38
39 @Phony.plausible?('+41 44 111 22 33').should be_true@
40
41 @Phony.plausible?('+41 44 111 22 33', cc: '41').should be_true@
42
43 @Phony.plausible?('+41 44 111 22 33', ndc: '44').should be_true@
44
45 @Phony.plausible?('+41 44 111 22 33', cc: '1').should be_false@
46
47 @Phony.plausible?('+41 44 111 22 33', ndc: '43').should be_false@
48
49 @Phony.plausible?('+41 44 111 22 33', cc: '41', ndc: '44').should be_true@
50
51 @Phony.plausible?('+41 44 111 22 33', cc: /4(0|2)/, ndc: /4(4|5)/).should be_false@
52
53 @Phony.plausible?('+41 44 111 22 33', cc: /4(0|1)/, ndc: /4(4|5)/).should be_true@
54
e0b473e @floere + anchors
authored
55 h3(#normalizing). Normalizing
f3ed13c @floere + README improved
authored
56
b868451 @floere + notes on plausible?
authored
57 This will often raise an error if you try normalizing a non E164-izable number (a number that does not contain enough information to be normalized into an E164 conform number). Use @Phony.plausible?@ for checking if it can be normalized first.
66bc80a @floere + updated README with information on #plausible?
authored
58
cedc4c2 @floere + phony rename
authored
59 @Phony.normalize('41443643533').should == '41443643533'@
f3ed13c @floere + README improved
authored
60
cedc4c2 @floere + phony rename
authored
61 @Phony.normalize('+41 44 364 35 33').should == '41443643533'@
f3ed13c @floere + README improved
authored
62
cedc4c2 @floere + phony rename
authored
63 @Phony.normalize('+41 44 364 35 33').should == '41443643533'@
f3ed13c @floere + README improved
authored
64
cedc4c2 @floere + phony rename
authored
65 @Phony.normalize('+41 800 11 22 33').should == '41800112233'@
f3ed13c @floere + README improved
authored
66
cedc4c2 @floere + phony rename
authored
67 @Phony.normalize('John: +41 44 364 35 33').should == '41443643533'@
f3ed13c @floere + README improved
authored
68
cedc4c2 @floere + phony rename
authored
69 @Phony.normalize('1 (703) 451-5115').should == '17034515115'@
f3ed13c @floere + README improved
authored
70
cedc4c2 @floere + phony rename
authored
71 @Phony.normalize('1-888-407-4747').should == '18884074747'@
f3ed13c @floere + README improved
authored
72
cedc4c2 @floere + phony rename
authored
73 @Phony.normalize('1.906.387.1698').should == '19063871698'@
f3ed13c @floere + README improved
authored
74
cedc4c2 @floere + phony rename
authored
75 @Phony.normalize('+41 (044) 364 35 33').should == '41443643533'@
f3ed13c @floere + README improved
authored
76
e0b473e @floere + anchors
authored
77 h3(#formatting). Formatting
f3ed13c @floere + README improved
authored
78
cedc4c2 @floere + phony rename
authored
79 @Phony.formatted('41443643532').should == '+41 44 364 35 32'@
f3ed13c @floere + README improved
authored
80
cedc4c2 @floere + phony rename
authored
81 @Phony.formatted('41800112233').should == '+41 800 11 22 33'@
f3ed13c @floere + README improved
authored
82
cedc4c2 @floere + phony rename
authored
83 @Phony.formatted('43198110').should == '+43 1 98110'@
f3ed13c @floere + README improved
authored
84
cedc4c2 @floere + phony rename
authored
85 @Phony.formatted('18705551122').should == '+1 870 555 1122'@
f3ed13c @floere + README improved
authored
86
e0b473e @floere + anchors
authored
87 h4(#international). International
f3ed13c @floere + README improved
authored
88
cedc4c2 @floere + phony rename
authored
89 @Phony.formatted('18091231234', :format => :international).should == '+1 809 123 1234'@
f3ed13c @floere + README improved
authored
90
cedc4c2 @floere + phony rename
authored
91 @Phony.formatted('43198110', :format => :international).should == '+43 1 98110'@
f3ed13c @floere + README improved
authored
92
cedc4c2 @floere + phony rename
authored
93 @Phony.formatted('43198110', :format => :international_absolute).should == '+43 1 98110'@
f3ed13c @floere + README improved
authored
94
cedc4c2 @floere + phony rename
authored
95 @Phony.formatted('33142278186', :format => :+).should == '+33 1 42 27 81 86'@
f3ed13c @floere + README improved
authored
96
cedc4c2 @floere + phony rename
authored
97 @Phony.formatted('43198110', :format => :international_relative).should == '0043 1 98110'@
f3ed13c @floere + README improved
authored
98
cedc4c2 @floere + phony rename
authored
99 @Phony.formatted('4233841148', :format => :international_relative).should == '00423 384 11 48'@
f3ed13c @floere + README improved
authored
100
e0b473e @floere + anchors
authored
101 h4(#spaces). With spaces
f3ed13c @floere + README improved
authored
102
cedc4c2 @floere + phony rename
authored
103 @Phony.formatted('18091231234', :format => :international, :spaces => '').should == '+18091231234'@
f3ed13c @floere + README improved
authored
104
cedc4c2 @floere + phony rename
authored
105 @Phony.formatted('43198110', :format => :international, :spaces => '').should == '+43198110'@
f3ed13c @floere + README improved
authored
106
cedc4c2 @floere + phony rename
authored
107 @Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'@
f3ed13c @floere + README improved
authored
108
cedc4c2 @floere + phony rename
authored
109 @Phony.formatted('33142278186', :format => :+, :spaces => '').should == '+33142278186'@
f3ed13c @floere + README improved
authored
110
cedc4c2 @floere + phony rename
authored
111 @Phony.formatted('43198110', :format => :international_relative, :spaces => '').should == '0043198110'@
f3ed13c @floere + README improved
authored
112
cedc4c2 @floere + phony rename
authored
113 @Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'@
f3ed13c @floere + README improved
authored
114
e0b473e @floere + anchors
authored
115 h4(#special). With special spaces
f3ed13c @floere + README improved
authored
116
cedc4c2 @floere + phony rename
authored
117 @Phony.formatted('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'@
f3ed13c @floere + README improved
authored
118
cedc4c2 @floere + phony rename
authored
119 @Phony.formatted('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'@
f3ed13c @floere + README improved
authored
120
cedc4c2 @floere + phony rename
authored
121 @Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'@
f3ed13c @floere + README improved
authored
122
cedc4c2 @floere + phony rename
authored
123 @Phony.formatted('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'@
f3ed13c @floere + README improved
authored
124
cedc4c2 @floere + phony rename
authored
125 @Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'@
f3ed13c @floere + README improved
authored
126
cedc4c2 @floere + phony rename
authored
127 @Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'@
f3ed13c @floere + README improved
authored
128
e0b473e @floere + anchors
authored
129 h4(#national). National
f3ed13c @floere + README improved
authored
130
cedc4c2 @floere + phony rename
authored
131 @Phony.formatted('41443643532', :format => :national).should == '044 364 35 32'@
f3ed13c @floere + README improved
authored
132
cedc4c2 @floere + phony rename
authored
133 @Phony.formatted('41800112233', :format => :national).should == '0800 11 22 33'@
f3ed13c @floere + README improved
authored
134
cedc4c2 @floere + phony rename
authored
135 @Phony.formatted('43198110', :format => :national).should == '01 98110'@
f3ed13c @floere + README improved
authored
136
e0b473e @floere + anchors
authored
137 h4(#local). Local
f3ed13c @floere + README improved
authored
138
cedc4c2 @floere + phony rename
authored
139 @Phony.formatted('41443643532', :format => :local).should == '364 35 32'@
f3ed13c @floere + README improved
authored
140
cedc4c2 @floere + phony rename
authored
141 @Phony.formatted('493038625454', :format => :local).should == '386 25454'@
f3ed13c @floere + README improved
authored
142
e0b473e @floere + anchors
authored
143 h3(#splitting). Splitting
f3ed13c @floere + README improved
authored
144
cedc4c2 @floere + phony rename
authored
145 @Phony.split('43198110').should == ['43', '1', '98110']@
f3ed13c @floere + README improved
authored
146
cedc4c2 @floere + phony rename
authored
147 @Phony.split('33112345678').should == ['33', '1', '12','34','56','78']@
f3ed13c @floere + README improved
authored
148
cedc4c2 @floere + phony rename
authored
149 @Phony.split('4976112345').should == ['49', '761', '123', '45']@
f3ed13c @floere + README improved
authored
150
9b37d4c @floere + italian phone numbers
authored
151 @Phony.split('3928061371').should == ['39', '2', '806', '1371']@
f3ed13c @floere + README improved
authored
152
cedc4c2 @floere + phony rename
authored
153 @Phony.split('41443643532').should == ['41', '44', '364', '35', '32']@
f3ed13c @floere + README improved
authored
154
cedc4c2 @floere + phony rename
authored
155 @Phony.split('15551115511').should == ['1', '555', '111', '5511']@
f3ed13c @floere + README improved
authored
156
cedc4c2 @floere + phony rename
authored
157 @Phony.split('6491234567').should == ['64', '9', '123', '4567']@
f3ed13c @floere + README improved
authored
158
596d7b4 @floere + Note about bang methods
authored
159 @Phony.split('41800334455').should == ['41', '800', '33', '44', '55']@
160
161 Note: There is also a ! version of each of these methods which
162 will destroy the original string and return a new (or old) one.
163 Just work only with the returned value, and you will be fine.
Something went wrong with that request. Please try again.