Skip to content
This repository
Newer
Older
100644 157 lines (81 sloc) 6.364 kb
cedc4c2f »
2010-11-04 + phony rename
1 h1. Phony
f3ed13c3 »
2010-11-04 + README improved
2
bd11c994 »
2012-02-27 + zendesk
3 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).
c87d7256 »
2011-10-11 + users
4
f3ed13c3 »
2010-11-04 + README improved
5 h2. Description
6
e650d67e »
2010-11-04 + let's not be too enthusiastic
7 This gem can normalize, format and split E164 numbers.
3a26fcc5 »
2010-11-17 + E164 link in README
8 "More about E164 numbers in this Wiki":http://en.wikipedia.org/wiki/E.164.
f3ed13c3 »
2010-11-04 + README improved
9
a17a5abb »
2011-01-03 + goal in README
10 The (admittedly crazy) *goal* of this Gem is to be able to format/split all phone numbers in the world.
11
fd4a668d »
2012-05-13 + Vietnam
12 Currently handles Afghan, Algerian, Austrian, Australian, Belgian, Brazilian, Chilean, Chinese, Croatian, Cuban, Czech, Danish, Dutch, Egyptian, French, German, Ghanan, Greek, Hungarian, Italian, Ireland, Lithuanian, Malaysian, Mexican, (The) Netherlands, 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.
4712a107 »
2011-02-03 ! typo
13 And to some extent, all others. Just try if it works for you.
03dc48d0 »
2010-11-15 - old code (80% replaced), + preparation for new features
14
03555a3b »
2011-01-01 + Countries list
15 If it doesn't, please "enter an issue":http://github.com/floere/phony/issues.
16
b18da2ac »
2010-11-16 + installation in readme
17 h2. Installation
18
3a26fcc5 »
2010-11-17 + E164 link in README
19 <pre><code>gem install phony</code></pre>
b18da2ac »
2010-11-16 + installation in readme
20
f3ed13c3 »
2010-11-04 + README improved
21 h2. Some examples
22
66bc80a8 »
2012-05-15 + updated README with information on #plausible?
23 h3. Plausibility
24
25 "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.
26
27 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.
28
29 @Phony.plausible?('0000000').should be_false@
30
31 @Phony.plausible?('hello').should be_false@
32
33 @Phony.plausible?('+41 44 111 22 33').should be_true@
34
35 @Phony.plausible?('+41 44 111 22 33', cc: '41').should be_true@
36
37 @Phony.plausible?('+41 44 111 22 33', ndc: '44').should be_true@
38
39 @Phony.plausible?('+41 44 111 22 33', cc: '1').should be_false@
40
41 @Phony.plausible?('+41 44 111 22 33', ndc: '43').should be_false@
42
43 @Phony.plausible?('+41 44 111 22 33', cc: '41', ndc: '44').should be_true@
44
45 @Phony.plausible?('+41 44 111 22 33', cc: /4(0|2)/, ndc: /4(4|5)/).should be_false@
46
47 @Phony.plausible?('+41 44 111 22 33', cc: /4(0|1)/, ndc: /4(4|5)/).should be_true@
48
f3ed13c3 »
2010-11-04 + README improved
49 h3. Normalizing
50
66bc80a8 »
2012-05-15 + updated README with information on #plausible?
51 Note: This method 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.
52
cedc4c2f »
2010-11-04 + phony rename
53 @Phony.normalize('41443643533').should == '41443643533'@
f3ed13c3 »
2010-11-04 + README improved
54
cedc4c2f »
2010-11-04 + phony rename
55 @Phony.normalize('+41 44 364 35 33').should == '41443643533'@
f3ed13c3 »
2010-11-04 + README improved
56
cedc4c2f »
2010-11-04 + phony rename
57 @Phony.normalize('+41 44 364 35 33').should == '41443643533'@
f3ed13c3 »
2010-11-04 + README improved
58
cedc4c2f »
2010-11-04 + phony rename
59 @Phony.normalize('+41 800 11 22 33').should == '41800112233'@
f3ed13c3 »
2010-11-04 + README improved
60
cedc4c2f »
2010-11-04 + phony rename
61 @Phony.normalize('John: +41 44 364 35 33').should == '41443643533'@
f3ed13c3 »
2010-11-04 + README improved
62
cedc4c2f »
2010-11-04 + phony rename
63 @Phony.normalize('1 (703) 451-5115').should == '17034515115'@
f3ed13c3 »
2010-11-04 + README improved
64
cedc4c2f »
2010-11-04 + phony rename
65 @Phony.normalize('1-888-407-4747').should == '18884074747'@
f3ed13c3 »
2010-11-04 + README improved
66
cedc4c2f »
2010-11-04 + phony rename
67 @Phony.normalize('1.906.387.1698').should == '19063871698'@
f3ed13c3 »
2010-11-04 + README improved
68
cedc4c2f »
2010-11-04 + phony rename
69 @Phony.normalize('+41 (044) 364 35 33').should == '41443643533'@
f3ed13c3 »
2010-11-04 + README improved
70
71 h3. Formatting
72
cedc4c2f »
2010-11-04 + phony rename
73 @Phony.formatted('41443643532').should == '+41 44 364 35 32'@
f3ed13c3 »
2010-11-04 + README improved
74
cedc4c2f »
2010-11-04 + phony rename
75 @Phony.formatted('41800112233').should == '+41 800 11 22 33'@
f3ed13c3 »
2010-11-04 + README improved
76
cedc4c2f »
2010-11-04 + phony rename
77 @Phony.formatted('43198110').should == '+43 1 98110'@
f3ed13c3 »
2010-11-04 + README improved
78
cedc4c2f »
2010-11-04 + phony rename
79 @Phony.formatted('18705551122').should == '+1 870 555 1122'@
f3ed13c3 »
2010-11-04 + README improved
80
81 h4. International
82
cedc4c2f »
2010-11-04 + phony rename
83 @Phony.formatted('18091231234', :format => :international).should == '+1 809 123 1234'@
f3ed13c3 »
2010-11-04 + README improved
84
cedc4c2f »
2010-11-04 + phony rename
85 @Phony.formatted('43198110', :format => :international).should == '+43 1 98110'@
f3ed13c3 »
2010-11-04 + README improved
86
cedc4c2f »
2010-11-04 + phony rename
87 @Phony.formatted('43198110', :format => :international_absolute).should == '+43 1 98110'@
f3ed13c3 »
2010-11-04 + README improved
88
cedc4c2f »
2010-11-04 + phony rename
89 @Phony.formatted('33142278186', :format => :+).should == '+33 1 42 27 81 86'@
f3ed13c3 »
2010-11-04 + README improved
90
cedc4c2f »
2010-11-04 + phony rename
91 @Phony.formatted('43198110', :format => :international_relative).should == '0043 1 98110'@
f3ed13c3 »
2010-11-04 + README improved
92
cedc4c2f »
2010-11-04 + phony rename
93 @Phony.formatted('4233841148', :format => :international_relative).should == '00423 384 11 48'@
f3ed13c3 »
2010-11-04 + README improved
94
95 h4. With spaces
96
cedc4c2f »
2010-11-04 + phony rename
97 @Phony.formatted('18091231234', :format => :international, :spaces => '').should == '+18091231234'@
f3ed13c3 »
2010-11-04 + README improved
98
cedc4c2f »
2010-11-04 + phony rename
99 @Phony.formatted('43198110', :format => :international, :spaces => '').should == '+43198110'@
f3ed13c3 »
2010-11-04 + README improved
100
cedc4c2f »
2010-11-04 + phony rename
101 @Phony.formatted('43198110', :format => :international_absolute, :spaces => '').should == '+43198110'@
f3ed13c3 »
2010-11-04 + README improved
102
cedc4c2f »
2010-11-04 + phony rename
103 @Phony.formatted('33142278186', :format => :+, :spaces => '').should == '+33142278186'@
f3ed13c3 »
2010-11-04 + README improved
104
cedc4c2f »
2010-11-04 + phony rename
105 @Phony.formatted('43198110', :format => :international_relative, :spaces => '').should == '0043198110'@
f3ed13c3 »
2010-11-04 + README improved
106
cedc4c2f »
2010-11-04 + phony rename
107 @Phony.formatted('4233841148', :format => :international_relative, :spaces => '').should == '004233841148'@
f3ed13c3 »
2010-11-04 + README improved
108
109 h4. With special spaces
110
cedc4c2f »
2010-11-04 + phony rename
111 @Phony.formatted('18091231234', :format => :international, :spaces => :-).should == '+1-809-123-1234'@
f3ed13c3 »
2010-11-04 + README improved
112
cedc4c2f »
2010-11-04 + phony rename
113 @Phony.formatted('43198110', :format => :international, :spaces => :-).should == '+43-1-98110'@
f3ed13c3 »
2010-11-04 + README improved
114
cedc4c2f »
2010-11-04 + phony rename
115 @Phony.formatted('43198110', :format => :international_absolute, :spaces => :-).should == '+43-1-98110'@
f3ed13c3 »
2010-11-04 + README improved
116
cedc4c2f »
2010-11-04 + phony rename
117 @Phony.formatted('33142278186', :format => :+, :spaces => :-).should == '+33-1-42-27-81-86'@
f3ed13c3 »
2010-11-04 + README improved
118
cedc4c2f »
2010-11-04 + phony rename
119 @Phony.formatted('43198110', :format => :international_relative, :spaces => :-).should == '0043-1-98110'@
f3ed13c3 »
2010-11-04 + README improved
120
cedc4c2f »
2010-11-04 + phony rename
121 @Phony.formatted('4233841148', :format => :international_relative, :spaces => :-).should == '00423-384-11-48'@
f3ed13c3 »
2010-11-04 + README improved
122
123 h4. National
124
cedc4c2f »
2010-11-04 + phony rename
125 @Phony.formatted('41443643532', :format => :national).should == '044 364 35 32'@
f3ed13c3 »
2010-11-04 + README improved
126
cedc4c2f »
2010-11-04 + phony rename
127 @Phony.formatted('41800112233', :format => :national).should == '0800 11 22 33'@
f3ed13c3 »
2010-11-04 + README improved
128
cedc4c2f »
2010-11-04 + phony rename
129 @Phony.formatted('43198110', :format => :national).should == '01 98110'@
f3ed13c3 »
2010-11-04 + README improved
130
131 h4. Local
132
cedc4c2f »
2010-11-04 + phony rename
133 @Phony.formatted('41443643532', :format => :local).should == '364 35 32'@
f3ed13c3 »
2010-11-04 + README improved
134
cedc4c2f »
2010-11-04 + phony rename
135 @Phony.formatted('493038625454', :format => :local).should == '386 25454'@
f3ed13c3 »
2010-11-04 + README improved
136
137 h3. Splitting
138
cedc4c2f »
2010-11-04 + phony rename
139 @Phony.split('43198110').should == ['43', '1', '98110']@
f3ed13c3 »
2010-11-04 + README improved
140
cedc4c2f »
2010-11-04 + phony rename
141 @Phony.split('33112345678').should == ['33', '1', '12','34','56','78']@
f3ed13c3 »
2010-11-04 + README improved
142
cedc4c2f »
2010-11-04 + phony rename
143 @Phony.split('4976112345').should == ['49', '761', '123', '45']@
f3ed13c3 »
2010-11-04 + README improved
144
9b37d4c1 »
2010-11-19 + italian phone numbers
145 @Phony.split('3928061371').should == ['39', '2', '806', '1371']@
f3ed13c3 »
2010-11-04 + README improved
146
cedc4c2f »
2010-11-04 + phony rename
147 @Phony.split('41443643532').should == ['41', '44', '364', '35', '32']@
f3ed13c3 »
2010-11-04 + README improved
148
cedc4c2f »
2010-11-04 + phony rename
149 @Phony.split('15551115511').should == ['1', '555', '111', '5511']@
f3ed13c3 »
2010-11-04 + README improved
150
cedc4c2f »
2010-11-04 + phony rename
151 @Phony.split('6491234567').should == ['64', '9', '123', '4567']@
f3ed13c3 »
2010-11-04 + README improved
152
596d7b43 »
2010-11-15 + Note about bang methods
153 @Phony.split('41800334455').should == ['41', '800', '33', '44', '55']@
154
155 Note: There is also a ! version of each of these methods which
156 will destroy the original string and return a new (or old) one.
157 Just work only with the returned value, and you will be fine.
Something went wrong with that request. Please try again.