open-companies-house 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -37,7 +37,12 @@ module CompaniesHouse
37
37
  def validate(number)
38
38
  number = number.to_s.strip # remove whitespace
39
39
 
40
- number = "0" + number if number.length == 7 # 0-pad for luck
40
+ # 0-pad 5 or 7 digit registration number
41
+ if number.match /(\D{2})(\d{5})$/
42
+ number = $1 + $2.rjust(6,"0")
43
+ elsif number.match /(\d{7}$)/
44
+ number = number.rjust(8, "0")
45
+ end
41
46
 
42
47
  companies_house_regex = Regexp.
43
48
  new("\\A(#{ALLOWED_PREFIXES * '|'})\\d{6}\\z")
@@ -1,3 +1,3 @@
1
1
  module CompaniesHouse
2
- VERSION = '0.2.4'.freeze
2
+ VERSION = '0.2.5'.freeze
3
3
  end
@@ -46,11 +46,29 @@ describe CompaniesHouse::Request do
46
46
  end
47
47
  end
48
48
 
49
+ it "does not 0-pads 8 digit registration numbers" do
50
+ company = subject.new "17495895"
51
+ company.instance_variable_get(:@registration_number).
52
+ should == "17495895"
53
+ end
54
+
49
55
  it "0-pads 7 digit registration numbers" do
50
56
  company = subject.new "7495895"
51
57
  company.instance_variable_get(:@registration_number).
52
58
  should == "07495895"
53
59
  end
60
+
61
+ it "0-pads 5 digit NI registration numbers" do
62
+ company = subject.new "NI27768"
63
+ company.instance_variable_get(:@registration_number).
64
+ should == "NI027768"
65
+ end
66
+
67
+ it "does not 0-pads 6 digit NI registration numbers" do
68
+ company = subject.new "NI127768"
69
+ company.instance_variable_get(:@registration_number).
70
+ should == "NI127768"
71
+ end
54
72
  end
55
73
 
56
74
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open-companies-house
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-12-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec