ean13 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3560d1d3bd6e0a9bb896a02d6ec4bc5d7a8ba055
4
+ data.tar.gz: 923ead966aa48093d90c8e679c8e8538f1c3daac
5
+ SHA512:
6
+ metadata.gz: c97981cb32ad497b7bd202f04f933a28b0d894cb931818fb983b63bd3d825d0cd28d318d9984e67ecd4e0661f2fb84529cafc8665839652d3d5d1658e6848d07
7
+ data.tar.gz: 958bdcdeea6af37d453feb3aefc73d41c87a3eb0b44260178c0dae9b58f0ba4ab4f784211a01efb17b350d910dc7972eefdd5a6e7cc7024899ce94e51ddedfe8
data/CHANGELOG CHANGED
@@ -1,5 +1,5 @@
1
- v1.4 (21st September 2009)
2
- - remove rails-ism. oops.
1
+ v2.0 (15th July 2017)
2
+ - Remove methods for converting to SANs
3
3
 
4
4
  v1.3 (11th July 2009)
5
5
  - add a bookland? method. Returns true if ean is a book EAN
data/README.markdown ADDED
@@ -0,0 +1,35 @@
1
+ A small class for generating and validating EAN-13's, the 13 digit codes found
2
+ on many products sold around the world.
3
+
4
+ # Installation
5
+
6
+ gem install ean13
7
+
8
+ # Usage
9
+
10
+ EAN13.new("0632737715836").valid?
11
+ => true
12
+
13
+ EAN13.valid?("0632737715836")
14
+ => true
15
+
16
+ EAN13.valid?("0632737715837")
17
+ => false
18
+
19
+ EAN13.complete("063273771583")
20
+ => "0632737715836"
21
+
22
+ EAN13.new("0632737715836").to_upc
23
+ => "632737715836"
24
+
25
+ EAN13.new("0632737715836").to_gtin
26
+ => "00632737715836"
27
+
28
+ # Further Reading
29
+
30
+ - http://en.wikipedia.org/wiki/European_Article_Number
31
+
32
+ # Contributing
33
+
34
+ Source code is publicly available @ http://github.com/yob/ean13.Patches
35
+ welcome, preferably via a git repo I can pull from.
data/lib/ean13.rb CHANGED
@@ -3,8 +3,8 @@ require 'rubygems'
3
3
  class EAN13
4
4
 
5
5
  class Version #:nodoc:
6
- Major = 1
7
- Minor = 4
6
+ Major = 2
7
+ Minor = 0
8
8
  Tiny = 0
9
9
 
10
10
  String = [Major, Minor, Tiny].join('.')
@@ -33,7 +33,7 @@ class EAN13
33
33
  return nil unless twelve.length == 12 && twelve.match(/\d{11}/)
34
34
 
35
35
  arr = (0..11).to_a.collect do |i|
36
- if (i+1) % 2 == 0
36
+ if (i+1).even?
37
37
  twelve[i,1].to_i * 3
38
38
  else
39
39
  twelve[i,1].to_i
@@ -56,14 +56,7 @@ class EAN13
56
56
  # http://www.bowker.com/index.php/component/content/article/3
57
57
  #
58
58
  def san?
59
- return nil unless valid?
60
-
61
- prefix = @number.to_s[0,6]
62
- if prefix == "079999" || prefix == "503067"
63
- true
64
- else
65
- false
66
- end
59
+ $stderr.puts "EAN13.san? was removed in ean13 v2.0"
67
60
  end
68
61
 
69
62
  # convert this EAN to a SAN. returns nil if the EAN doesn't contain
@@ -73,16 +66,7 @@ class EAN13
73
66
  # error if it's not
74
67
  #
75
68
  def to_san
76
- unless Kernel.const_defined?("SAN")
77
- begin
78
- gem 'san'
79
- require 'san'
80
- rescue Exception => e
81
- raise LoadError, "Could not load require SAN library. Try installing the san rubygem."
82
- end
83
- end
84
- return nil unless san?
85
- SAN.complete(@number[6,6])
69
+ $stderr.puts "EAN13.to_san was removed in ean13 v2.0"
86
70
  end
87
71
 
88
72
  def to_gtin
data/spec/ean13_spec.rb CHANGED
@@ -1,70 +1,46 @@
1
- $LOAD_PATH << File.dirname(__FILE__) + "/../lib"
2
-
3
- require 'spec'
4
1
  require 'ean13'
5
2
 
6
3
  describe "The EAN13 class" do
7
4
  it "should identify a valid EAN13" do
8
- EAN13.new("9781843549161").valid?.should be_true
5
+ expect(EAN13.new("9781843549161").valid?).to be_truthy
9
6
  end
10
7
 
11
8
  it "should identify a valid EAN13" do
12
- EAN13.valid?("9781843549161").should be_true
13
- EAN13.valid?(9781843549161).should be_true
14
- EAN13.valid?("9790702228727").should be_true
15
- EAN13.valid?("9790702228727").should be_true
16
- EAN13.valid?("0602498351321").should be_true
9
+ expect(EAN13.valid?("9781843549161")).to be_truthy
10
+ expect(EAN13.valid?(9781843549161)).to be_truthy
11
+ expect(EAN13.valid?("9790702228727")).to be_truthy
12
+ expect(EAN13.valid?("9790702228727")).to be_truthy
13
+ expect(EAN13.valid?("0602498351321")).to be_truthy
17
14
  end
18
15
 
19
16
  it "should identify an invalid EAN13" do
20
- EAN13.valid?(nil).should be_false
21
- EAN13.valid?("978184354916").should be_false
22
- EAN13.valid?(Array).should be_false
23
- EAN13.valid?(Array.new).should be_false
24
- EAN13.valid?("9781843549162").should be_false
17
+ expect(EAN13.valid?(nil)).to be_falsey
18
+ expect(EAN13.valid?("978184354916")).to be_falsey
19
+ expect(EAN13.valid?(Array)).to be_falsey
20
+ expect(EAN13.valid?(Array.new)).to be_falsey
21
+ expect(EAN13.valid?("9781843549162")).to be_falsey
25
22
  end
26
23
 
27
24
  it "should identify a bookland EAN13" do
28
- EAN13.new("9781843549161").bookland?.should be_true
29
- EAN13.new("9791843549160").bookland?.should be_true
30
- EAN13.new("9791843549161").bookland?.should be_false
31
- EAN13.new("sdw32423").bookland?.should be_false
32
- EAN13.new("632737715836").bookland?.should be_false
25
+ expect(EAN13.new("9781843549161").bookland?).to be_truthy
26
+ expect(EAN13.new("9791843549160").bookland?).to be_truthy
27
+ expect(EAN13.new("9791843549161").bookland?).to be_falsey
28
+ expect(EAN13.new("sdw32423").bookland?).to be_falsey
29
+ expect(EAN13.new("632737715836").bookland?).to be_falsey
33
30
  end
34
31
 
35
32
  it "should calculate a EAN13 check digit correctly" do
36
- EAN13.complete("978184354916").should eql("9781843549161")
37
- EAN13.complete(978184354916).should eql("9781843549161")
33
+ expect(EAN13.complete("978184354916")).to eql("9781843549161")
34
+ expect(EAN13.complete(978184354916)).to eql("9781843549161")
38
35
  end
39
36
 
40
37
  it "should convert to a UPC correctly" do
41
- EAN13.new("9781843549161").to_upc.should be_nil
42
- EAN13.new("0632737715836").to_upc.should eql("632737715836")
38
+ expect(EAN13.new("9781843549161").to_upc).to be_nil
39
+ expect(EAN13.new("0632737715836").to_upc).to eql("632737715836")
43
40
  end
44
41
 
45
42
  it "should convert to a GTIN-14 correctly" do
46
- EAN13.new("9781843549161").to_gtin.should eql("09781843549161")
47
- EAN13.new("0632737715836").to_gtin.should eql("00632737715836")
48
- end
49
-
50
- it "should recognise the presence of an embedded SAN" do
51
- EAN13.new("0799999013725").san?.should be_true
52
- EAN13.new("5030670159260").san?.should be_true
53
- EAN13.new("0632737715836").san?.should be_false
54
- end
55
-
56
- it "should convert to a SAN correctly" do
57
-
58
- begin
59
- require 'san'
60
- rescue LoadError
61
- warn "WARNING: can't test EAN13#to_san, san library not available"
62
- end
63
-
64
- if Kernel.const_defined?("SAN")
65
- EAN13.new("0799999013725").to_san.should eql("9013725")
66
- EAN13.new("5030670159260").to_san.should eql("0159263")
67
- EAN13.new("0632737715836").to_san.should be_nil
68
- end
43
+ expect(EAN13.new("9781843549161").to_gtin).to eql("09781843549161")
44
+ expect(EAN13.new("0632737715836").to_gtin).to eql("00632737715836")
69
45
  end
70
46
  end
metadata CHANGED
@@ -1,60 +1,80 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: ean13
3
- version: !ruby/object:Gem::Version
4
- version: 1.4.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
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
- date: 2009-09-21 00:00:00 +10:00
13
- default_executable:
14
- dependencies: []
15
-
11
+ date: 2017-07-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
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: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
16
41
  description: a (very) small library for working with EAN-13 codes
17
42
  email: jimmy@deefa.com
18
43
  executables: []
19
-
20
44
  extensions: []
21
-
22
45
  extra_rdoc_files: []
23
-
24
- files:
25
- - lib/ean13.rb
26
- - MIT-LICENSE
27
- - README.rdoc
46
+ files:
28
47
  - CHANGELOG
29
- has_rdoc: true
30
- homepage: http://github.com/yob/ean13/tree/master
31
- licenses: []
32
-
48
+ - MIT-LICENSE
49
+ - README.markdown
50
+ - lib/ean13.rb
51
+ - spec/ean13_spec.rb
52
+ homepage: http://github.com/yob/ean13
53
+ licenses:
54
+ - MIT
55
+ metadata: {}
33
56
  post_install_message:
34
- rdoc_options:
35
- - --title
57
+ rdoc_options:
58
+ - "--title"
36
59
  - EAN-13
37
- - --line-numbers
38
- require_paths:
60
+ - "--line-numbers"
61
+ require_paths:
39
62
  - lib
40
- required_ruby_version: !ruby/object:Gem::Requirement
41
- requirements:
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
42
65
  - - ">="
43
- - !ruby/object:Gem::Version
44
- version: "0"
45
- version:
46
- required_rubygems_version: !ruby/object:Gem::Requirement
47
- requirements:
66
+ - !ruby/object:Gem::Version
67
+ version: 1.9.3
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
48
70
  - - ">="
49
- - !ruby/object:Gem::Version
50
- version: "0"
51
- version:
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
52
73
  requirements: []
53
-
54
- rubyforge_project: yob-projects
55
- rubygems_version: 1.3.5
74
+ rubyforge_project:
75
+ rubygems_version: 2.6.11
56
76
  signing_key:
57
- specification_version: 3
77
+ specification_version: 4
58
78
  summary: a (very) small library for working with EAN-13 codes
59
- test_files:
79
+ test_files:
60
80
  - spec/ean13_spec.rb
data/README.rdoc DELETED
@@ -1,35 +0,0 @@
1
- A small class for generating and validating EAN-13's, the 13 digit codes found
2
- on many products sold around the world.
3
-
4
- = Installation
5
-
6
- gem install ean13
7
-
8
- = Usage
9
-
10
- EAN13.new("0632737715836").valid?
11
- => true
12
-
13
- EAN13.valid?("0632737715836")
14
- => true
15
-
16
- EAN13.valid?("0632737715837")
17
- => false
18
-
19
- EAN13.complete("063273771583")
20
- => "0632737715836"
21
-
22
- EAN13.new("0632737715836").to_upc
23
- => "632737715836"
24
-
25
- EAN13.new("0632737715836").to_gtin
26
- => "00632737715836"
27
-
28
- = Further Reader
29
-
30
- - http://en.wikipedia.org/wiki/European_Article_Number
31
-
32
- = Contributing
33
-
34
- Source code is publicly available @ http://github.com/yob/ean13/tree/master.
35
- Patches welcome, preferably via a git repo I can pull from.