nifval 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,11 @@ function nifval(nif){
2
2
  // NIF not provided
3
3
  if(!nif) return false;
4
4
 
5
+ // Add zeros to the left if applyable, and accept lowercase
6
+ if(nif.length < 9)
7
+ nif = repeat("0",9-nif.length) + nif;
8
+ nif = nif.toUpperCase();
9
+
5
10
  // Format
6
11
  if(!nif.match(/^[A-Z]{1}\d{7}[A-Z0-9]{1}$/) && !nif.match(/^[0-9]{8}[A-Z]{1}$/)) return false;
7
12
 
@@ -36,3 +41,10 @@ function nifval(nif){
36
41
  }
37
42
  }
38
43
  }
44
+
45
+ function repeat(s, n) {
46
+ var r="";
47
+ for (var a=0;a<n;a++)
48
+ r+=s;
49
+ return r;
50
+ }
@@ -16,6 +16,10 @@ module Nifval
16
16
  # NIF not provided
17
17
  return false if nif.nil?
18
18
 
19
+ # Add zeros to the left if applyable, and accept lowercase
20
+ nif = nif.rjust(9,'0')
21
+ nif = nif.upcase
22
+
19
23
  # Format
20
24
  return false if
21
25
  !nif.match(/^[A-Z]{1}\d{7}[A-Z0-9]{1}$/) && !nif.match(/^[0-9]{8}[A-Z]{1}$/)
@@ -1,3 +1,3 @@
1
1
  module NifVal
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -60,6 +60,19 @@ describe Nifval do
60
60
  end
61
61
  end
62
62
 
63
+ # Good format
64
+ context "when we check alternatively-formatted strings" do
65
+ # Accept with length < 9
66
+ it "should return OK" do
67
+ nif_validity "T", true
68
+ end
69
+
70
+ # Accept lowercase
71
+ it "should return OK" do
72
+ nif_validity "00000000t", true
73
+ end
74
+ end
75
+
63
76
  # Bad format
64
77
  context "when we check for badly-formatted strings" do
65
78
  it "should return ERROR" do
@@ -1,7 +1,12 @@
1
- function nifval(nif){
1
+ nifvfunction nifval(nif){
2
2
  // NIF not provided
3
3
  if(!nif) return false;
4
4
 
5
+ // Add zeros to the left if applyable, and accept lowercase
6
+ if(nif.length < 9)
7
+ nif = repeat("0",9-nif.length) + nif;
8
+ nif = nif.toUpperCase();
9
+
5
10
  // Format
6
11
  if(!nif.match(/^[A-Z]{1}\d{7}[A-Z0-9]{1}$/) && !nif.match(/^[0-9]{8}[A-Z]{1}$/)) return false;
7
12
 
@@ -36,3 +41,10 @@ function nifval(nif){
36
41
  }
37
42
  }
38
43
  }
44
+
45
+ function repeat(s, n) {
46
+ var r="";
47
+ for (var a=0;a<n;a++)
48
+ r+=s;
49
+ return r;
50
+ }
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nifval
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 1
10
+ version: 0.2.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Albert Bellonch