san 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/CHANGELOG +8 -0
  2. data/README.rdoc +4 -4
  3. data/lib/san.rb +25 -1
  4. data/spec/san_spec.rb +17 -1
  5. metadata +15 -5
data/CHANGELOG ADDED
@@ -0,0 +1,8 @@
1
+ v1.2 (25th November 2008)
2
+ - Add functions for conversion to a US and UK-based GLN
3
+
4
+ v1.1 (11th September 2008)
5
+ - Fix an embarassing typo
6
+
7
+ v1.0 (August 2008)
8
+ - Initial Release
data/README.rdoc CHANGED
@@ -6,14 +6,14 @@ a unique global identifier used in the book and publishing industries.
6
6
  SAN.new("9013725").valid?
7
7
  => true
8
8
 
9
- SAN.valid_san?("9013725")
9
+ SAN.valid?("9013725")
10
10
  => true
11
11
 
12
- SAN.valid_san?("9013726")
12
+ SAN.valid?("9013726")
13
13
  => false
14
14
 
15
- SAN.check_digit?("901372")
16
- => 5
15
+ SAN.complete("901372")
16
+ => "9013725"
17
17
 
18
18
  = Further Reader
19
19
 
data/lib/san.rb CHANGED
@@ -1,8 +1,10 @@
1
+ require 'ean13'
2
+
1
3
  class SAN
2
4
 
3
5
  class Version #:nodoc:
4
6
  Major = 1
5
- Minor = 1
7
+ Minor = 2
6
8
  Tiny = 0
7
9
 
8
10
  String = [Major, Minor, Tiny].join('.')
@@ -16,6 +18,28 @@ class SAN
16
18
  SAN.valid? @number
17
19
  end
18
20
 
21
+ # convert this SAN into a US based Global Location Number.
22
+ #
23
+ # see:
24
+ # - http://en.wikipedia.org/wiki/Global_Location_Number
25
+ # - http://www.bisg.org/conferences/UConnnect_2007.pdf
26
+ #
27
+ def to_us_gln
28
+ return nil unless valid?
29
+ "079999#{@number}"
30
+ end
31
+
32
+ # convert this SAN into a UK based Global Location Number.
33
+ #
34
+ # see:
35
+ # - http://en.wikipedia.org/wiki/Global_Location_Number
36
+ # - http://www.bisg.org/conferences/UConnnect_2007.pdf
37
+ #
38
+ def to_uk_gln
39
+ return nil unless valid?
40
+ EAN13.complete("503067#{@number[0,6]}")
41
+ end
42
+
19
43
  def self.valid?(san)
20
44
  san = san.to_s
21
45
  san.length == 7 && san == SAN.complete(san[0,6])
data/spec/san_spec.rb CHANGED
@@ -13,7 +13,7 @@ describe "The SAN class" do
13
13
  SAN.valid?(9013725).should be_true
14
14
  SAN.valid?("902865X").should be_true
15
15
  end
16
-
16
+
17
17
  it "should identify an invalid SAN" do
18
18
  SAN.valid?(nil).should be_false
19
19
  SAN.valid?("902865").should be_false
@@ -25,4 +25,20 @@ describe "The SAN class" do
25
25
  SAN.complete("901372").should eql("9013725")
26
26
  SAN.complete(901372).should eql("9013725")
27
27
  end
28
+
29
+ it "should correctly convert to a US based GLN" do
30
+ # valid
31
+ SAN.new("9013725").to_us_gln.should eql("0799999013725")
32
+
33
+ # invalid
34
+ SAN.new("9013724").to_us_gln.should be_nil
35
+ end
36
+
37
+ it "should correctly convert to a UK based GLN" do
38
+ # valid
39
+ SAN.new("0159263").to_uk_gln.should eql("5030670159260")
40
+
41
+ # invalid
42
+ SAN.new("9013724").to_uk_gln.should be_nil
43
+ end
28
44
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: san
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,10 +9,19 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-09-11 00:00:00 +10:00
12
+ date: 2008-11-25 00:00:00 +11:00
13
13
  default_executable:
14
- dependencies: []
15
-
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: ean13
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
16
25
  description: a (very) small library for working with Standard Address Numbers.
17
26
  email: jimmy@deefa.com
18
27
  executables: []
@@ -25,6 +34,7 @@ files:
25
34
  - lib/san.rb
26
35
  - MIT-LICENSE
27
36
  - README.rdoc
37
+ - CHANGELOG
28
38
  has_rdoc: true
29
39
  homepage: http://github.com/yob/san/tree/master
30
40
  post_install_message:
@@ -49,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
59
  requirements: []
50
60
 
51
61
  rubyforge_project: san
52
- rubygems_version: 1.2.0
62
+ rubygems_version: 1.3.1
53
63
  signing_key:
54
64
  specification_version: 2
55
65
  summary: a (very) small library for working with Standard Address Numbers.