ean13 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/CHANGELOG +3 -0
  2. data/lib/ean13.rb +28 -1
  3. data/spec/ean13_spec.rb +12 -0
  4. metadata +14 -5
data/CHANGELOG CHANGED
@@ -1,2 +1,5 @@
1
+ v1.1 (25th November 2008)
2
+ - Add support for detecting and extracting embedded SANs
3
+
1
4
  v1.0 (22nd October 2008)
2
5
  - Initial Release
data/lib/ean13.rb CHANGED
@@ -1,8 +1,11 @@
1
+ require 'rubygems'
2
+ require 'san'
3
+
1
4
  class EAN13
2
5
 
3
6
  class Version #:nodoc:
4
7
  Major = 1
5
- Minor = 0
8
+ Minor = 1
6
9
  Tiny = 0
7
10
 
8
11
  String = [Major, Minor, Tiny].join('.')
@@ -44,6 +47,30 @@ class EAN13
44
47
  twelve + check.to_s
45
48
  end
46
49
 
50
+ # Returns true if this EAN has an embedded SAN
51
+ #
52
+ # For more info on SANs, see
53
+ # http://www.bowker.com/index.php/component/content/article/3
54
+ #
55
+ def san?
56
+ return nil unless valid?
57
+
58
+ prefix = @number.to_s[0,6]
59
+ if prefix == "079999" || prefix == "503067"
60
+ true
61
+ else
62
+ false
63
+ end
64
+ end
65
+
66
+ # convert this EAN to a SAN. returns nil if the EAN doesn't contain
67
+ # an embedded SAN.
68
+ #
69
+ def to_san
70
+ return nil unless san?
71
+ SAN.complete(@number[6,6])
72
+ end
73
+
47
74
  def to_gtin
48
75
  return nil unless self.valid?
49
76
  "0#{@number}"
data/spec/ean13_spec.rb CHANGED
@@ -38,4 +38,16 @@ describe "The EAN13 class" do
38
38
  EAN13.new("9781843549161").to_gtin.should eql("09781843549161")
39
39
  EAN13.new("0632737715836").to_gtin.should eql("00632737715836")
40
40
  end
41
+
42
+ it "should recognise the presence of an embedded SAN" do
43
+ EAN13.new("0799999013725").san?.should be_true
44
+ EAN13.new("5030670159260").san?.should be_true
45
+ EAN13.new("0632737715836").san?.should be_false
46
+ end
47
+
48
+ it "should convert to a SAN correctly" do
49
+ EAN13.new("0799999013725").to_san.should eql("9013725")
50
+ EAN13.new("5030670159260").to_san.should eql("0159263")
51
+ EAN13.new("0632737715836").to_san.should be_nil
52
+ end
41
53
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ean13
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.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-10-22 00:00:00 +11: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: san
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 EAN-13 codes
17
26
  email: jimmy@deefa.com
18
27
  executables: []
@@ -50,7 +59,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
59
  requirements: []
51
60
 
52
61
  rubyforge_project: yob-projects
53
- rubygems_version: 1.2.0
62
+ rubygems_version: 1.3.1
54
63
  signing_key:
55
64
  specification_version: 2
56
65
  summary: a (very) small library for working with EAN-13 codes