msisdn-za 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,7 @@
1
+ log/*
2
+ =======
3
+ .DS_Store
4
+ pkg/*
5
+ pkg/**/*
6
+ *.gem
7
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Craig Paterson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ = msisdn-za
2
+
3
+ South African MSISDN parser based on the work of armanddp at http://github.com/armanddp/msisdn
4
+
5
+ It simplified in the sense that it is only intended for use with ZA numbers
6
+ and makes no attempt to deal with any other countries.
7
+
8
+ Some of the code structure has been kept the same as the original gem, since
9
+ I needed it to be a drop-in replacement. That said, the two probably won't
10
+ play nicely together.
11
+
12
+ == Requirements
13
+
14
+ None that I can think of..
15
+
16
+ == Install
17
+
18
+ sudo gem install msisdn-za
19
+
20
+ == Copyright
21
+
22
+ Copyright (c) 2010 Craig Paterson. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "msisdn-za"
8
+ gem.summary = %Q{Parses South Afican MSISDNs. That is all.}
9
+ gem.description = %Q{ZA MSISDN parser simplified, based on work by armanddp}
10
+ gem.email = "darksavant@gmail.com"
11
+ gem.homepage = "http://github.com/craigp/msisdn-za"
12
+ gem.authors = ["Craig Paterson"]
13
+ gem.add_development_dependency "shoulda", ">= 2.11.1"
14
+ gem.version = File.exist?('VERSION') ? File.read('VERSION') : ""
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ begin
30
+ require 'rcov/rcovtask'
31
+ Rcov::RcovTask.new do |test|
32
+ test.libs << 'test'
33
+ test.pattern = 'test/**/test_*.rb'
34
+ test.verbose = true
35
+ end
36
+ rescue LoadError
37
+ task :rcov do
38
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
39
+ end
40
+ end
41
+
42
+ task :test => :check_dependencies
43
+
44
+ task :default => :test
45
+
46
+ require 'rake/rdoctask'
47
+ Rake::RDocTask.new do |rdoc|
48
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
49
+
50
+ rdoc.rdoc_dir = 'rdoc'
51
+ rdoc.title = "msisdn #{version}"
52
+ rdoc.rdoc_files.include('README*')
53
+ rdoc.rdoc_files.include('lib/**/*.rb')
54
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1
data/lib/msisdn.rb ADDED
@@ -0,0 +1,56 @@
1
+ $:.unshift(File.dirname(__FILE__))
2
+
3
+ class Msisdn
4
+ attr_accessor :original, :national_number, :dialing_code,
5
+ :country_code, :local_dialing_code
6
+
7
+ # leaving the default country code in to stop shit breaking where
8
+ # i used the old msisdn gem
9
+ def initialize(msisdn, default_country_code = '27')
10
+ @original = msisdn
11
+ # remove dashes and spaces
12
+ msisdn.gsub!( /[\s()\-a-zA-Z]/, '')
13
+ # remove + prefix if there is one
14
+ msisdn.gsub!(/\+/, '')
15
+
16
+ # check if the ZA international dialing code is included, and remove it
17
+ # only remove the first occurence of 27, and only if its in the beginning of the string
18
+ msisdn.sub!(/27/, '') if msisdn =~ /^27/
19
+ # pad it on the left with zeros just in case
20
+ @msisdn = msisdn.rjust(10, '0')
21
+ @msisdn =~ /(\d{3})(\d{7})/
22
+ # so now the first three digits *should* be the local dialing code
23
+ @local_dialing_code, @national_number = $1, $2
24
+
25
+ # these are for compatability with the old gem
26
+ @dialing_code = @local_dialing_code
27
+ @country_code = default_country_code
28
+ end
29
+
30
+ def international
31
+ "27#{@local_dialing_code.gsub(/^0+/, '')}#{@national_number}"
32
+ end
33
+
34
+ def international_with_prefix
35
+ "+#{international}"
36
+ end
37
+
38
+ def valid?
39
+ valid_national? && valid_local_dialing_code?
40
+ end
41
+
42
+ # a national number is valid if it has 7 digits and doesn't start with zeroes
43
+ def valid_national?
44
+ @national_number =~ /^\d{7}$/ && @national_number !~ /^0/
45
+ end
46
+
47
+ # a valid local dialing code should be three digits long and start with a zero
48
+ def valid_local_dialing_code?
49
+ @local_dialing_code =~ /^[\d][^0]{2}$/
50
+ end
51
+
52
+ def to_s
53
+ international
54
+ end
55
+
56
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/msisdn.rb'}"
9
+ puts "Loading msisdn gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'msisdn'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,51 @@
1
+ require 'helper'
2
+
3
+ class TestMsisdn < Test::Unit::TestCase
4
+
5
+ context "an valid internationalized msisdn (with or without prefix)" do
6
+
7
+ setup do
8
+ @msisdn = Msisdn.new('+27835559629')
9
+ @msisdn2 = Msisdn.new('27835559629')
10
+ end
11
+
12
+ should "return the correct international number" do
13
+ assert_equal '27835559629', @msisdn.international
14
+ assert_equal @msisdn.international, @msisdn2.international
15
+ end
16
+
17
+ should "be valid" do
18
+ assert @msisdn.valid?
19
+ assert @msisdn2.valid?
20
+ end
21
+
22
+ end
23
+
24
+ context "a valid non-internationalized msisdn" do
25
+
26
+ setup do
27
+ @msisdn = Msisdn.new('0835559629')
28
+ end
29
+
30
+ should "return the correct country code and international number" do
31
+ assert_equal '27', @msisdn.country_code
32
+ assert_equal '27835559629', @msisdn.international
33
+ end
34
+
35
+ should "be valid" do
36
+ assert @msisdn.valid?
37
+ end
38
+
39
+ end
40
+
41
+ context "an invalid msidn" do
42
+
43
+ should "not be valid" do
44
+ msisdn = Msisdn.new('278259629')
45
+ puts msisdn.inspect
46
+ assert !msisdn.valid?
47
+ end
48
+
49
+ end
50
+
51
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: msisdn-za
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Craig Paterson
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-22 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: shoulda
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 33
29
+ segments:
30
+ - 2
31
+ - 11
32
+ - 1
33
+ version: 2.11.1
34
+ type: :development
35
+ version_requirements: *id001
36
+ description: ZA MSISDN parser simplified, based on work by armanddp
37
+ email: darksavant@gmail.com
38
+ executables: []
39
+
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - LICENSE
44
+ - README.rdoc
45
+ files:
46
+ - .document
47
+ - .gitignore
48
+ - LICENSE
49
+ - README.rdoc
50
+ - Rakefile
51
+ - VERSION
52
+ - lib/msisdn.rb
53
+ - script/console
54
+ - test/helper.rb
55
+ - test/test_msisdn.rb
56
+ has_rdoc: true
57
+ homepage: http://github.com/craigp/msisdn-za
58
+ licenses: []
59
+
60
+ post_install_message:
61
+ rdoc_options:
62
+ - --charset=UTF-8
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ hash: 3
71
+ segments:
72
+ - 0
73
+ version: "0"
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ hash: 3
80
+ segments:
81
+ - 0
82
+ version: "0"
83
+ requirements: []
84
+
85
+ rubyforge_project:
86
+ rubygems_version: 1.3.7
87
+ signing_key:
88
+ specification_version: 3
89
+ summary: Parses South Afican MSISDNs. That is all.
90
+ test_files:
91
+ - test/helper.rb
92
+ - test/test_msisdn.rb