Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 41cbfce
Showing
7 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
# Splits a national number into a fixed size NDC and rest. | ||
# | ||
class E164::NDC::Austria < E164::NDC::Prefix | ||
|
||
self.max_ndc_size = 4 | ||
self.format = '%s %s' | ||
|
||
# prefix length => | ||
# country code => national prefix length | ||
self.ndcs = { | ||
1 => [ | ||
'1' | ||
], # Wien | ||
2 => [ | ||
'57', # - | ||
'59', # - | ||
'67', # Mobile Services | ||
'68', # Mobile Services | ||
'89' # Routing Number | ||
], # - | ||
3 => [ | ||
'316', # Graz | ||
'501', # - | ||
'502', # - | ||
'503', # - | ||
'504', # - | ||
'505', # - | ||
'506', # - | ||
'507', # - | ||
'508', # - | ||
'509', # - | ||
'512', # Innsbruck | ||
'517', # - | ||
'644', # Mobile Services | ||
'650', # Mobile Services | ||
'651', # Mobile Services | ||
'652', # Mobile Services | ||
'653', # Mobile Services | ||
'655', # Mobile Services | ||
'657', # Mobile Services | ||
'659', # Mobile Services | ||
'660', # Mobile Services | ||
'661', # Mobile Services | ||
'662', # Salzburg | ||
'663', # Mobile Services | ||
'664', # Mobile Services | ||
'665', # Mobile Services | ||
'666', # Mobile Services | ||
'667', # Mobile Services | ||
'668', # Mobile Services | ||
'669', # Mobile Services | ||
'710', # Service Number | ||
'711', # Service Number | ||
'718', # Service Number | ||
'720', # | ||
'730', # Service Number | ||
'732', # Linz | ||
'740', # Service Number | ||
'780', # Service Number | ||
'800', # Service Number | ||
'802', # Service Number | ||
'804', # Service Number | ||
'810', # Service Number | ||
'820', # Service Number | ||
'821', # Service Number | ||
'828', # Service Number | ||
'900', # Service Number | ||
'901', # Service Number | ||
'930', # Service Number | ||
'931', # Service Number | ||
'939' # Service Number | ||
] | ||
} | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Splits a national number into a fixed size NDC and rest. | ||
# | ||
class E164::NDC::FixedSize | ||
|
||
class_inheritable_accessor :format | ||
|
||
def initialize(national_code_length) | ||
@national_code_length = national_code_length | ||
end | ||
|
||
def split(number) | ||
number = number.dup | ||
[number.slice!(0..@national_code_length-1), number] | ||
end | ||
|
||
def formatted(number) | ||
(format || '%s %s') % split(number) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Splits a national number using a prefix code. | ||
# | ||
class E164::NDC::Prefix | ||
|
||
class_inheritable_accessor :max_ndc_size, :ndcs, :format | ||
|
||
def self.split(number) | ||
number = number.dup | ||
presumed_code = '' | ||
1.upto(max_ndc_size) do |i| | ||
presumed_code << number.slice!(0..0) | ||
sized_ndcs = ndcs[i] | ||
break unless sized_ndcs && !sized_ndcs.include?(presumed_code) | ||
end | ||
return [presumed_code, number] | ||
end | ||
|
||
def self.formatted(number) | ||
(format || '%s %s %s %s') % split(number) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.dirname(__FILE__) + '/../../../spec_helper' | ||
|
||
describe E164::NDC::Austria do | ||
|
||
attr_reader :splitter | ||
before(:each) do | ||
@splitter = E164::NDC::Austria | ||
end | ||
|
||
describe "split" do | ||
it "should handle Vienna" do | ||
splitter.split('1123456789123').should == ['1', '123456789123'] | ||
end | ||
it "should handle some mobile services" do | ||
splitter.split('6712345678912').should == ['67', '12345678912'] | ||
end | ||
it "should handle Graz" do | ||
splitter.split('3161234567891').should == ['316', '1234567891'] | ||
end | ||
it "should handle Rohrau" do | ||
splitter.split('2164123456789').should == ['2164', '123456789'] | ||
end | ||
end | ||
|
||
describe "formatted" do | ||
it "should format Vienna" do | ||
splitter.formatted('198110').should == '1 98110' | ||
end | ||
it "should format some mobile services" do | ||
splitter.formatted('6712345678912').should == '67 12345678912' | ||
end | ||
it "should format Graz" do | ||
splitter.formatted('3161234567891').should == '316 1234567891' | ||
end | ||
it "should format Rohrau" do | ||
splitter.formatted('2164123456789').should == '2164 123456789' | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
require File.dirname(__FILE__) + '/../../../spec_helper' | ||
|
||
describe E164::NDC::FixedSize do | ||
|
||
attr_reader :splitter | ||
|
||
describe "size 1" do | ||
before(:each) do | ||
@splitter = E164::NDC::FixedSize.new 1 | ||
end | ||
|
||
describe "formatted" do | ||
it "should format correctly" do | ||
splitter.formatted('12345678901234').should == '1 2345678901234' | ||
end | ||
end | ||
end | ||
describe "size 2" do | ||
before(:each) do | ||
@splitter = E164::NDC::FixedSize.new 2 | ||
end | ||
|
||
describe "formatted" do | ||
it "should format correctly" do | ||
splitter.formatted('12345678901234').should == '12 345678901234' | ||
end | ||
end | ||
end | ||
describe "size 3" do | ||
before(:each) do | ||
@splitter = E164::NDC::FixedSize.new 3 | ||
end | ||
|
||
describe "formatted" do | ||
it "should format correctly" do | ||
splitter.formatted('12345678901234').should == '123 45678901234' | ||
end | ||
end | ||
end | ||
describe "size 4" do | ||
before(:each) do | ||
@splitter = E164::NDC::FixedSize.new 4 | ||
end | ||
|
||
describe "formatted" do | ||
it "should format correctly" do | ||
splitter.formatted('12345678901234').should == '1234 5678901234' | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
require File.dirname(__FILE__) + '/../spec_helper' | ||
|
||
describe E164 do | ||
|
||
describe "split" do | ||
it "should handle austrian numbers" do | ||
E164.split('43112345678').should == ['43', '1', '12345678'] | ||
end | ||
it "should handle french numbers" do | ||
E164.split('33112345678').should == ['33', '1', '12345678'] | ||
end | ||
it "should handle german numbers opinionatedly" do | ||
E164.split('49123123456').should == ['49', '123', '123456'] | ||
end | ||
it "should handle italian numbers opinionatedly" do | ||
E164.split('39123123456').should == ['39', '123', '123456'] | ||
end | ||
it "should handle swiss numbers" do | ||
E164.split('41443643532').should == ['41', '44', '3643532'] | ||
end | ||
it "should handle US numbers" do | ||
E164.split('15551115511').should == ['1', '555', '1115511'] | ||
end | ||
it "should handle new zealand numbers" do | ||
E164.split('6491231234').should == ['64', '9', '1231234'] | ||
end | ||
end | ||
|
||
describe "formatted" do | ||
describe "default" do | ||
it "should format austrian numbers" do | ||
E164.formatted('43198110').should == '+43 1 98110' | ||
end | ||
end | ||
describe "international" do | ||
it "should format austrian numbers" do | ||
E164.formatted('43198110', :format => :international).should == '+43 1 98110' | ||
end | ||
end | ||
end | ||
|
||
end |