msisdn-za 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -15,7 +15,18 @@ None that I can think of..
15
15
 
16
16
  == Install
17
17
 
18
- sudo gem install msisdn-za
18
+ sudo gem install msisdn-za
19
+
20
+ == Usage
21
+
22
+ In rails, put this in one of your environment files:
23
+
24
+ gem.config 'msisdn-za', :lib => 'msisdn'
25
+
26
+ Elsewhere, just:
27
+
28
+ gem 'msisdn-za'
29
+ require 'msisdn'
19
30
 
20
31
  == Copyright
21
32
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
data/lib/msisdn.rb CHANGED
@@ -27,30 +27,33 @@ class Msisdn
27
27
  @country_code = default_country_code
28
28
  end
29
29
 
30
- def international
30
+ def international_number
31
31
  "27#{@local_dialing_code.gsub(/^0+/, '')}#{@national_number}"
32
32
  end
33
33
 
34
- def international_with_prefix
34
+ def international_number_with_prefix
35
35
  "+#{international}"
36
36
  end
37
37
 
38
38
  def valid?
39
- valid_national? && valid_local_dialing_code?
39
+ valid_national_number? && valid_local_dialing_code?
40
40
  end
41
41
 
42
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/
43
+ def valid_national_number?
44
+ # removing the check for leading zero, since it is breaking things,
45
+ # like the number 0730711059
46
+ # @national_number =~ /^\d{7}$/ && @national_number !~ /^0/
47
+ return (@national_number =~ /^\d{7}$/) ? true : false
45
48
  end
46
49
 
47
50
  # a valid local dialing code should be three digits long and start with a zero
48
51
  def valid_local_dialing_code?
49
- @local_dialing_code =~ /^[\d][^0]{2}$/
52
+ return (@local_dialing_code =~ /^[\d][^0]{2}$/) ? true : false
50
53
  end
51
54
 
52
55
  def to_s
53
- international
56
+ international_number
54
57
  end
55
58
 
56
59
  end
data/msisdn-za.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{msisdn-za}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Craig Paterson"]
12
- s.date = %q{2010-07-22}
12
+ s.date = %q{2010-09-22}
13
13
  s.description = %q{ZA MSISDN parser simplified, based on work by armanddp}
14
14
  s.email = %q{darksavant@gmail.com}
15
15
  s.extra_rdoc_files = [
data/test/test_msisdn.rb CHANGED
@@ -10,8 +10,8 @@ class TestMsisdn < Test::Unit::TestCase
10
10
  end
11
11
 
12
12
  should "return the correct international number" do
13
- assert_equal '27835559629', @msisdn.international
14
- assert_equal @msisdn.international, @msisdn2.international
13
+ assert_equal '27835559629', @msisdn.international_number
14
+ assert_equal @msisdn.international_number, @msisdn2.international_number
15
15
  end
16
16
 
17
17
  should "be valid" do
@@ -29,12 +29,10 @@ class TestMsisdn < Test::Unit::TestCase
29
29
 
30
30
  should "return the correct country code and international number" do
31
31
  assert_equal '27', @msisdn.country_code
32
- assert_equal '27835559629', @msisdn.international
32
+ assert_equal '27835559629', @msisdn.international_number
33
33
  end
34
34
 
35
35
  should "be valid" do
36
- puts "CLASS: #{@msisdn.class.name}"
37
- puts "DIAL CODE: #{@msisdn.local_dialing_code}"
38
36
  assert @msisdn.valid?
39
37
  end
40
38
 
@@ -44,10 +42,22 @@ class TestMsisdn < Test::Unit::TestCase
44
42
 
45
43
  should "not be valid" do
46
44
  msisdn = Msisdn.new('278259629')
47
- puts msisdn.inspect
48
45
  assert !msisdn.valid?
49
46
  end
50
47
 
51
48
  end
49
+
50
+ context "a known broken msisdn" do
51
+ setup do
52
+ @msisdn = Msisdn.new("0730670000")
53
+ end
54
+
55
+ should "sort its shit out ffs" do
56
+ assert_equal @msisdn.local_dialing_code, "073"
57
+ assert_equal @msisdn.national_number, "0670000"
58
+ assert_equal @msisdn.international_number, "27730670000"
59
+ assert @msisdn.valid?
60
+ end
61
+ end
52
62
 
53
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: msisdn-za
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 3
10
- version: 0.1.3
9
+ - 4
10
+ version: 0.1.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Craig Paterson
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-07-22 00:00:00 +02:00
18
+ date: 2010-09-22 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency