ean13 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 (3) hide show
  1. data/lib/ean13.rb +12 -2
  2. data/spec/ean13_spec.rb +12 -3
  3. metadata +4 -13
data/lib/ean13.rb CHANGED
@@ -1,11 +1,10 @@
1
1
  require 'rubygems'
2
- require 'san'
3
2
 
4
3
  class EAN13
5
4
 
6
5
  class Version #:nodoc:
7
6
  Major = 1
8
- Minor = 1
7
+ Minor = 2
9
8
  Tiny = 0
10
9
 
11
10
  String = [Major, Minor, Tiny].join('.')
@@ -66,7 +65,18 @@ class EAN13
66
65
  # convert this EAN to a SAN. returns nil if the EAN doesn't contain
67
66
  # an embedded SAN.
68
67
  #
68
+ # requires the SAN library to be loaded or available. Will raise an
69
+ # error if it's not
70
+ #
69
71
  def to_san
72
+ unless Kernel.const_defined?("SAN")
73
+ begin
74
+ gem 'san'
75
+ require 'san'
76
+ rescue Exception => e
77
+ raise LoadError, "Could not load require SAN library. Try installing the san rubygem."
78
+ end
79
+ end
70
80
  return nil unless san?
71
81
  SAN.complete(@number[6,6])
72
82
  end
data/spec/ean13_spec.rb CHANGED
@@ -46,8 +46,17 @@ describe "The EAN13 class" do
46
46
  end
47
47
 
48
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
49
+
50
+ begin
51
+ require 'san'
52
+ rescue LoadError
53
+ warn "WARNING: can't test EAN13#to_san, san library not available"
54
+ end
55
+
56
+ if Kernel.const_defined?("SAN")
57
+ EAN13.new("0799999013725").to_san.should eql("9013725")
58
+ EAN13.new("5030670159260").to_san.should eql("0159263")
59
+ EAN13.new("0632737715836").to_san.should be_nil
60
+ end
52
61
  end
53
62
  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.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Healy
@@ -9,19 +9,10 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-11-25 00:00:00 +11:00
12
+ date: 2009-02-25 00:00:00 +11:00
13
13
  default_executable:
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:
14
+ dependencies: []
15
+
25
16
  description: a (very) small library for working with EAN-13 codes
26
17
  email: jimmy@deefa.com
27
18
  executables: []