Permalink
Browse files

+ romania, best effort, + 1.1.3

  • Loading branch information...
1 parent 1924b3c commit e32f33e34b8394f21f72d6b435bfa734bdec7cc1 @floere committed Nov 30, 2010
Showing with 38 additions and 2 deletions.
  1. +1 −0 lib/phony.rb
  2. +1 −1 lib/phony/countries/all_other.rb
  3. +30 −0 lib/phony/countries/romania.rb
  4. +1 −1 phony.gemspec
  5. +5 −0 spec/lib/phony_spec.rb
View
@@ -27,6 +27,7 @@
require File.expand_path '../phony/countries/hungary', __FILE__
require File.expand_path '../phony/countries/italy', __FILE__
require File.expand_path '../phony/countries/netherlands', __FILE__
+require File.expand_path '../phony/countries/romania', __FILE__
require File.expand_path '../phony/countries/sweden', __FILE__
require File.expand_path '../phony/country_codes', __FILE__
@@ -63,7 +63,7 @@ def self.mapping
'36' => Countries::Hungary,
'39' => Countries::Italy,
- '40' => fixed(2), # TODO Romania
+ '40' => Countries::Romania,
'41' => fixed(2, # Switzerland (Confederation of)
:local_format => [3, 2, 2],
:service_local_format => [3, 3],
@@ -0,0 +1,30 @@
+# Romanian phone numbers.
+#
+# http://en.wikipedia.org/wiki/Romania_telephone_area_codes
+#
+Phony::Countries::Romania = Phony::Country.configured :local_format => [3, 4], # Also captures 3, 3 on a fallback.
+ :local_special_format => [3, 3],
+ :ndc_fallback_length => 3,
+ :ndc_mapping => {
+ :landline => [
+ '21', # Bucureşti
+ '31', # Bucureşti
+ ],
+ :mobile => [
+ '71',
+ '72',
+ '73',
+ '74',
+ '75',
+ '76',
+ '77',
+ '78',
+ ],
+ :service => [
+ '112',
+ '800',
+ '900',
+ '903',
+ '906',
+ ]
+ }
View
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'phony'
- s.version = '1.1.2'
+ s.version = '1.1.3'
s.authors = ['Florian Hanke']
s.email = 'florian.hanke+phony@gmail.com'
s.homepage = 'http://github.com/floere/phony'
View
@@ -36,6 +36,11 @@
it "should handle polish numbers" do
Phony.split('48121123123').should == ['48', '12', '1', '123', '123']
end
+ it 'handles romanian numbers' do
+ Phony.split('40211231234').should == ['40', '21', '123', '1234']
+ Phony.split('40721231234').should == ['40', '72', '123', '1234']
+ Phony.split('40249123123').should == ['40', '249', '123', '123']
+ end
it "should handle swedish numbers" do
Phony.split('46812345678').should == ['46', '8', '12345678']
Phony.split('46111234567').should == ['46', '11', '1234567']

2 comments on commit e32f33e

omg ;o

Christmas comes early!

Also, I seriously had no clue about the data on 99.5% of that wikipedia page.
The rules for landlines including county code stuff seem somewhat complicated, at least in Romania's case, so i'd see them more easily implemented as either lambdas or regular expressions.

Do you think that would come with a tolerable performance hit ?

Owner

floere replied Nov 30, 2010

Hey Andrei

You must be the man with one of my top ten favorite profile images!
Glad you like it :)

Using a regexp or a lambda would come with an acceptable performance hit, as it would only be incurred when encountering a Romanian number and completely leave all other countries fast.

But it would be preferrable if we could solve it with the existing code/system. As soon as I hit a phone system that's too strange, I'll add lambda support. Now, that time might or might not have come… Let's see. I have to say, Romania has one of the more complicated phone number structures. Or had, I'm not so sure.

Can you take a look at http://en.wikipedia.org/wiki/Romania_telephone_area_codes and verify my assumptions below, if you have time?
The part I'm unsure about is whether most of it is still in place, or if just the part under "Present Day Telephone Codes" is currently valid. I tried reading the Romanian documents and came quite far, but many words I did not understand, so I'm rather unsure. Cool language though!

What I deduced is this:
The structure is 40-company+countycode-local, or 40-mobile-local, or 40-special-local.
Position 1: 40 - country code
Position 2: NDC (company identifier digit plus county code) ranging from 2 to 3 digits (if one removes the 0, which is added by Phony if rendering with :format => :national, and removed if rendered with :format => :international) The only geographical places that use a 2 digit Code are Bucureşti and Ilfov (they use 21 for Romtelecom and 31 for other landlines). All other use a 3 digit code with 2 or 3 prefixed, identifying the company, as with Bucureşti and Ilfov. Added to that we have special numbers like 800 (no-charge), or 112 (emergency).
Position 3 and 4: A local number, split into 3 and 4 digits in Bucureşti and Ilfov, and split into 3 and 3 digits in all other places. So +40 31 123 123, for example.

Does this seem right to you? Can you maybe try Phony a little with different Romanian numbers and see if it is ok? (Or even better, add more specs? :) )

Note that Phony.split and Phony.formatted need a full E164 compliant number (meaning with country code, digits only). You can use Phony.normalize to get a digit only number should you have special chars in it. Also see http://floere.github.com/phony/examples.html.

Cheers and thanks for the interest!

Please sign in to comment.