no_phone 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ .rvmrc
5
+ .rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in no_phone.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,24 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ no_phone (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+ diff-lcs (1.1.2)
10
+ rspec (2.5.0)
11
+ rspec-core (~> 2.5.0)
12
+ rspec-expectations (~> 2.5.0)
13
+ rspec-mocks (~> 2.5.0)
14
+ rspec-core (2.5.1)
15
+ rspec-expectations (2.5.0)
16
+ diff-lcs (~> 1.1.2)
17
+ rspec-mocks (2.5.0)
18
+
19
+ PLATFORMS
20
+ ruby
21
+
22
+ DEPENDENCIES
23
+ no_phone!
24
+ rspec
data/README.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ = No Phone
2
+ == The Norwegian Phone Number Normalizer
3
+
4
+ Attempts to ensure that there is only one way to write norwegian phone numbers.
5
+
6
+ After normalization a norwegian phone number should be bare bones without
7
+ national code (e.g. 90779024 if you entered +4790779024).
8
+
9
+ International numbers should all be prefixed with a +.
10
+
11
+ A number is considered to be international if it begins with + or 00 but not +47 or 0047.
12
+
13
+ Lacking complete knowledge of the phone system this is based on common sense and especially for foregin phones there might be many ways to reach the same phone enabling a sneaky user to enter undetected duplicates.
14
+
15
+
16
+ == Usage
17
+
18
+ gem install no_phone
19
+
20
+
21
+ require 'no_phone'
22
+ NoPhone.normalize "0047 (123) 45-678"
23
+ => "12345678"
24
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ module NoPhone
2
+ VERSION = "0.0.1"
3
+ end
data/lib/no_phone.rb ADDED
@@ -0,0 +1,13 @@
1
+ module NoPhone
2
+
3
+ def self.normalize(number)
4
+ number ||= ""
5
+ number = number.gsub(/[.\- \t\r\n\(\)]/, '')
6
+ number.gsub!(/^(\+)(.*)/) { |m| $1 + $2.gsub(/\+/, '') }
7
+ number.gsub!(/^00/, '+')
8
+ number.gsub!(/^\+47/, '')
9
+ number.gsub!(/^\+*0+/, '+')
10
+ number.gsub!(/^47/, '') if number.size > 8
11
+ number
12
+ end
13
+ end
data/no_phone.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "no_phone/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "no_phone"
7
+ s.version = NoPhone::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Simen Svale Skogsrud, Katrina Owen"]
10
+ s.email = ["katrina@bengler.no"]
11
+ s.homepage = "http://rubygems.org/gems/no_phone"
12
+ s.summary = %q{Norwegian phone number scrubber}
13
+ s.description = %q{Standardizes norwegian phone numbers, and leaves international numbers unchanged.}
14
+
15
+ s.rubyforge_project = "no_phone"
16
+
17
+ s.add_development_dependency('rspec')
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
@@ -0,0 +1,97 @@
1
+ require 'spec_helper'
2
+
3
+ describe NoPhone, "#normalize" do
4
+ context "Norwegian numbers" do
5
+ let(:number) { "12345678" }
6
+
7
+ context "with country code" do
8
+ it "deletes prepended country code (47)" do
9
+ NoPhone.normalize("4712345678").should == number
10
+ end
11
+
12
+ it "deletes prepended 0047" do
13
+ NoPhone.normalize("004712345678").should == number
14
+ end
15
+
16
+ it "deletes prepended +47" do
17
+ NoPhone.normalize("+4712345678").should == number
18
+ end
19
+
20
+ it "leaves extra digits intact" do
21
+ NoPhone.normalize("+47123456789").should == "#{number}9"
22
+ end
23
+
24
+ it "removes extraneous +signs" do
25
+ NoPhone.normalize("++4712345678").should == number
26
+ end
27
+ end
28
+
29
+ context "without country code" do
30
+ it "leaves extra digits intact" do
31
+ NoPhone.normalize("123456789").should == "#{number}9"
32
+ end
33
+ end
34
+
35
+ it "strips extraneous surrounding whitespace" do
36
+ NoPhone.normalize("\t\n \r\n12345678 \t\r\n\n ").should == number
37
+ end
38
+
39
+ it "strips all internal whitespace" do
40
+ NoPhone.normalize("12 345 67 8").should == number
41
+ end
42
+
43
+ it "strips dashes" do
44
+ NoPhone.normalize("12-34-56-78").should == number
45
+ end
46
+
47
+ it "strips periods" do
48
+ NoPhone.normalize("12.34.56.78").should == number
49
+ end
50
+
51
+ it "strips parentheses" do
52
+ NoPhone.normalize("(123)45678").should == number
53
+ end
54
+
55
+ end
56
+
57
+ context "International numbers" do
58
+ let(:number) { "+123456789" }
59
+
60
+ it "replaces 0 with +" do
61
+ NoPhone.normalize("0123456789").should == number
62
+ end
63
+
64
+ it "replaces 00 with +" do
65
+ NoPhone.normalize("00123456789").should == number
66
+ end
67
+
68
+ it "leaves + alone" do
69
+ NoPhone.normalize("+123456789").should == number
70
+ end
71
+
72
+ it "strips extraneous +signs" do
73
+ NoPhone.normalize("++123456789").should == number
74
+ end
75
+
76
+ it "strips extraneous surrounding whitespace" do
77
+ NoPhone.normalize("\t\n \r\n+123456789 \t\r\n\n ").should == number
78
+ end
79
+
80
+ it "strips all internal whitespace" do
81
+ NoPhone.normalize("+12 345 67 89").should == number
82
+ end
83
+
84
+ it "strips dashes" do
85
+ NoPhone.normalize("+12-34-56-789").should == number
86
+ end
87
+
88
+ it "strips periods" do
89
+ NoPhone.normalize("+12.34.56.789").should == number
90
+ end
91
+
92
+ it "strips parentheses" do
93
+ NoPhone.normalize("+(123)456789").should == number
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+
4
+ require 'no_phone'
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: no_phone
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Simen Svale Skogsrud, Katrina Owen
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-26 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :development
32
+ version_requirements: *id001
33
+ description: Standardizes norwegian phone numbers, and leaves international numbers unchanged.
34
+ email:
35
+ - katrina@bengler.no
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
45
+ - Gemfile.lock
46
+ - README.rdoc
47
+ - Rakefile
48
+ - lib/no_phone.rb
49
+ - lib/no_phone/version.rb
50
+ - no_phone.gemspec
51
+ - spec/normalize_spec.rb
52
+ - spec/spec_helper.rb
53
+ has_rdoc: true
54
+ homepage: http://rubygems.org/gems/no_phone
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project: no_phone
81
+ rubygems_version: 1.3.7
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Norwegian phone number scrubber
85
+ test_files:
86
+ - spec/normalize_spec.rb
87
+ - spec/spec_helper.rb