san 1.3.0 → 1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG +6 -0
- data/README.markdown +24 -0
- data/lib/san.rb +1 -2
- data/spec/san_spec.rb +15 -18
- metadata +70 -45
- data/README.rdoc +0 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1a3d2c1178a921555a0b01449b09dbda1181194a
|
4
|
+
data.tar.gz: b32c554b8b5d901014b40d7b2855e3cbe1c375cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e92218081172f5381e445f06119a4f61f1cda798298e68e4844474211f47b96a273923219add412d00e1aa39aad4f336188b234d9cb409c7fd6372045cc23df3
|
7
|
+
data.tar.gz: b668ce99015a0c615edd7b0e6cd22176a4f8d8878781c5d66cd00b1ef17b4bf2dcfedd0309c38c090fa4ed5416ed92bb8c4bcb520a11e0c69fbb128000e0d995
|
data/CHANGELOG
CHANGED
data/README.markdown
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
A small class for generating and validating Standard Address Numbers (SAN),
|
2
|
+
a unique global identifier used in the book and publishing industries.
|
3
|
+
|
4
|
+
# Installation
|
5
|
+
|
6
|
+
gem install san
|
7
|
+
|
8
|
+
# Usage
|
9
|
+
|
10
|
+
SAN.new("9013725").valid?
|
11
|
+
=> true
|
12
|
+
|
13
|
+
SAN.valid?("9013725")
|
14
|
+
=> true
|
15
|
+
|
16
|
+
SAN.valid?("9013726")
|
17
|
+
=> false
|
18
|
+
|
19
|
+
SAN.complete("901372")
|
20
|
+
=> "9013725"
|
21
|
+
|
22
|
+
# Further Reading
|
23
|
+
|
24
|
+
- https://www.myidentifiers.com.au/san/about
|
data/lib/san.rb
CHANGED
@@ -4,7 +4,7 @@ class SAN
|
|
4
4
|
|
5
5
|
class Version #:nodoc:
|
6
6
|
Major = 1
|
7
|
-
Minor =
|
7
|
+
Minor = 4
|
8
8
|
Tiny = 0
|
9
9
|
|
10
10
|
String = [Major, Minor, Tiny].join('.')
|
@@ -50,7 +50,6 @@ class SAN
|
|
50
50
|
six_digit_san = six_digit_san.to_s
|
51
51
|
return nil unless six_digit_san.length == 6 && six_digit_san.match(/\d{6}/)
|
52
52
|
|
53
|
-
#sum = (0..5).to_a.sum { |i| six_digit_san[i,1].to_i * (7-i) }
|
54
53
|
arr = (0..5).to_a.collect { |i| six_digit_san[i,1].to_i * (7-i) }
|
55
54
|
sum = arr.inject { |sum, n| sum + n }
|
56
55
|
check = 11 - (sum % 11)
|
data/spec/san_spec.rb
CHANGED
@@ -1,45 +1,42 @@
|
|
1
|
-
$LOAD_PATH << File.dirname(__FILE__) + "/../lib"
|
2
|
-
|
3
|
-
require 'spec'
|
4
1
|
require 'san'
|
5
2
|
|
6
3
|
describe "The SAN class" do
|
7
4
|
it "should identify a valid SAN" do
|
8
|
-
SAN.new("9013725").valid
|
5
|
+
expect(SAN.new("9013725").valid?).to be_truthy
|
9
6
|
end
|
10
7
|
|
11
8
|
it "should identify a valid SAN" do
|
12
|
-
SAN.valid?("9013725").
|
13
|
-
SAN.valid?(9013725).
|
14
|
-
SAN.valid?("902865X").
|
9
|
+
expect(SAN.valid?("9013725")).to be_truthy
|
10
|
+
expect(SAN.valid?(9013725)).to be_truthy
|
11
|
+
expect(SAN.valid?("902865X")).to be_truthy
|
15
12
|
end
|
16
13
|
|
17
14
|
it "should identify an invalid SAN" do
|
18
|
-
SAN.valid?(nil).
|
19
|
-
SAN.valid?("902865").
|
20
|
-
SAN.valid?(Array).
|
21
|
-
SAN.valid?(Array.new).
|
15
|
+
expect(SAN.valid?(nil)).to be_falsey
|
16
|
+
expect(SAN.valid?("902865")).to be_falsey
|
17
|
+
expect(SAN.valid?(Array)).to be_falsey
|
18
|
+
expect(SAN.valid?(Array.new)).to be_falsey
|
22
19
|
end
|
23
20
|
|
24
21
|
it "should calculate a SAN check digit correctly" do
|
25
|
-
SAN.complete("901372").
|
26
|
-
SAN.complete(901372).
|
22
|
+
expect(SAN.complete("901372")).to eql("9013725")
|
23
|
+
expect(SAN.complete(901372)).to eql("9013725")
|
27
24
|
end
|
28
25
|
|
29
26
|
it "should correctly convert to a US based GLN" do
|
30
27
|
# valid
|
31
|
-
SAN.new("9013725").to_us_gln.
|
32
|
-
SAN.new("9029761").to_us_gln.
|
28
|
+
expect(SAN.new("9013725").to_us_gln).to eql("0799999013725")
|
29
|
+
expect(SAN.new("9029761").to_us_gln).to eql("0799999029764")
|
33
30
|
|
34
31
|
# invalid
|
35
|
-
SAN.new("9013724").to_us_gln.
|
32
|
+
expect(SAN.new("9013724").to_us_gln).to be_nil
|
36
33
|
end
|
37
34
|
|
38
35
|
it "should correctly convert to a UK based GLN" do
|
39
36
|
# valid
|
40
|
-
SAN.new("0159263").to_uk_gln.
|
37
|
+
expect(SAN.new("0159263").to_uk_gln).to eql("5030670159260")
|
41
38
|
|
42
39
|
# invalid
|
43
|
-
SAN.new("9013724").to_uk_gln.
|
40
|
+
expect(SAN.new("9013724").to_uk_gln).to be_nil
|
44
41
|
end
|
45
42
|
end
|
metadata
CHANGED
@@ -1,69 +1,94 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: san
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.4'
|
5
5
|
platform: ruby
|
6
|
-
authors:
|
6
|
+
authors:
|
7
7
|
- James Healy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
dependencies:
|
15
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2017-07-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
16
14
|
name: ean13
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
17
20
|
type: :runtime
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
20
|
-
requirements:
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
21
31
|
- - ">="
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version:
|
24
|
-
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
25
55
|
description: a (very) small library for working with Standard Address Numbers.
|
26
56
|
email: jimmy@deefa.com
|
27
57
|
executables: []
|
28
|
-
|
29
58
|
extensions: []
|
30
|
-
|
31
59
|
extra_rdoc_files: []
|
32
|
-
|
33
|
-
files:
|
34
|
-
- lib/san.rb
|
35
|
-
- MIT-LICENSE
|
36
|
-
- README.rdoc
|
60
|
+
files:
|
37
61
|
- CHANGELOG
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
62
|
+
- MIT-LICENSE
|
63
|
+
- README.markdown
|
64
|
+
- lib/san.rb
|
65
|
+
- spec/san_spec.rb
|
66
|
+
homepage: http://github.com/yob/san
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
42
70
|
post_install_message:
|
43
|
-
rdoc_options:
|
44
|
-
- --title
|
71
|
+
rdoc_options:
|
72
|
+
- "--title"
|
45
73
|
- SAN
|
46
|
-
- --line-numbers
|
47
|
-
require_paths:
|
74
|
+
- "--line-numbers"
|
75
|
+
require_paths:
|
48
76
|
- lib
|
49
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
-
requirements:
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
51
79
|
- - ">="
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version:
|
54
|
-
|
55
|
-
|
56
|
-
requirements:
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: 1.9.3
|
82
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
57
84
|
- - ">="
|
58
|
-
- !ruby/object:Gem::Version
|
59
|
-
version:
|
60
|
-
version:
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: '0'
|
61
87
|
requirements: []
|
62
|
-
|
63
|
-
|
64
|
-
rubygems_version: 1.3.5
|
88
|
+
rubyforge_project:
|
89
|
+
rubygems_version: 2.6.11
|
65
90
|
signing_key:
|
66
|
-
specification_version:
|
91
|
+
specification_version: 4
|
67
92
|
summary: a (very) small library for working with Standard Address Numbers.
|
68
|
-
test_files:
|
93
|
+
test_files:
|
69
94
|
- spec/san_spec.rb
|
data/README.rdoc
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
A small class for generating and validating Standard Address Numbers (SAN),
|
2
|
-
a unique global identifier used in the book and publishing industries.
|
3
|
-
|
4
|
-
= Usage
|
5
|
-
|
6
|
-
SAN.new("9013725").valid?
|
7
|
-
=> true
|
8
|
-
|
9
|
-
SAN.valid?("9013725")
|
10
|
-
=> true
|
11
|
-
|
12
|
-
SAN.valid?("9013726")
|
13
|
-
=> false
|
14
|
-
|
15
|
-
SAN.complete("901372")
|
16
|
-
=> "9013725"
|
17
|
-
|
18
|
-
= Further Reader
|
19
|
-
|
20
|
-
- http://www.bowker.com/index.php/component/content/article/3
|
21
|
-
- http://www.thorpe.com.au/services/services_san.htm
|