yob-san 1.0 → 1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/CHANGELOG +3 -0
  2. data/README.rdoc +4 -4
  3. data/lib/san.rb +25 -1
  4. data/spec/san_spec.rb +18 -1
  5. metadata +4 -3
data/CHANGELOG CHANGED
@@ -1,3 +1,6 @@
1
+ v1.2 (25th November 2008)
2
+ - Add functions for conversion to a US and UK-based GLN
3
+
1
4
  v1.1 (11th September 2008)
2
5
  - Fix an embarassing typo
3
6
 
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 = 3
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
+ EAN13.complete("079999#{@number[0,6]}")
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,21 @@ 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
+ SAN.new("9029761").to_us_gln.should eql("0799999029764")
33
+
34
+ # invalid
35
+ SAN.new("9013724").to_us_gln.should be_nil
36
+ end
37
+
38
+ it "should correctly convert to a UK based GLN" do
39
+ # valid
40
+ SAN.new("0159263").to_uk_gln.should eql("5030670159260")
41
+
42
+ # invalid
43
+ SAN.new("9013724").to_uk_gln.should be_nil
44
+ end
28
45
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yob-san
3
3
  version: !ruby/object:Gem::Version
4
- version: "1.0"
4
+ version: "1.3"
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-13 00:00:00 -07:00
12
+ date: 2009-05-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -28,6 +28,7 @@ files:
28
28
  - CHANGELOG
29
29
  has_rdoc: true
30
30
  homepage: http://github.com/yob/san/tree/master
31
+ licenses:
31
32
  post_install_message:
32
33
  rdoc_options:
33
34
  - --title
@@ -50,7 +51,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
51
  requirements: []
51
52
 
52
53
  rubyforge_project:
53
- rubygems_version: 1.2.0
54
+ rubygems_version: 1.3.5
54
55
  signing_key:
55
56
  specification_version: 2
56
57
  summary: a (very) small library for working with Standard Address Numbers.