pabarcode 0.0.1
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.
- data/README.rdoc +18 -0
- data/Rakefile +15 -0
- data/barcode_test.rb +13 -0
- data/lib/pabarcode.rb +46 -0
- data/pabarcode.gemspec +30 -0
- metadata +65 -0
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
= PAbarcode
|
2
|
+
|
3
|
+
Ruby gem for supporting opeartions on various types of barcodes.
|
4
|
+
|
5
|
+
|
6
|
+
== Install
|
7
|
+
|
8
|
+
gem install pabarcode --source http://gemcutter.org
|
9
|
+
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
|
13
|
+
You just require pabarcode and you can use the PABarcode::Barcode class as follows:
|
14
|
+
|
15
|
+
barcode12 = "123456789012"
|
16
|
+
bc = PABarcode::Barcode.new(barcode12)
|
17
|
+
barcode_with_check_digit = bc.get_ean_13
|
18
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
|
5
|
+
Echoe.new('pabarcode', '0.0.1') do |p|
|
6
|
+
p.description = "Helper classes for working with various barcode types"
|
7
|
+
p.url = "http://github.com/amiridis/pabarcode"
|
8
|
+
p.author = "Petros Amiridis"
|
9
|
+
p.email = "petros@amiridis.net"
|
10
|
+
p.ignore_pattern = ["tmp/*", "script/*"]
|
11
|
+
p.development_dependencies = []
|
12
|
+
end
|
13
|
+
|
14
|
+
Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext}
|
15
|
+
|
data/barcode_test.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "lib/pabarcode"
|
2
|
+
require "test/unit"
|
3
|
+
|
4
|
+
include PAbarcode
|
5
|
+
|
6
|
+
class BarcodeTest < Test::Unit::TestCase
|
7
|
+
def test_get_ean_13
|
8
|
+
assert_equal("5123456789123", Barcode.new("512345678912").get_ean_13)
|
9
|
+
assert_equal("5205324352841", Barcode.new("520532435284").get_ean_13)
|
10
|
+
assert_equal("1234567890128", Barcode.new("123456789012").get_ean_13)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
data/lib/pabarcode.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
module PAbarcode
|
2
|
+
class Barcode
|
3
|
+
attr_reader :barcode
|
4
|
+
|
5
|
+
def initialize(barcode)
|
6
|
+
@barcode = barcode
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_ean_13
|
10
|
+
add_check_digit(@barcode)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def add_check_digit(barcode)
|
16
|
+
return barcode unless barcode.length == 12
|
17
|
+
barcode + calc_check_digit(barcode)
|
18
|
+
end
|
19
|
+
|
20
|
+
def calc_check_digit(barcode)
|
21
|
+
ss = 0 # sum
|
22
|
+
se = 0 # sum of numbers in even positions
|
23
|
+
so = 0 # sum of numbers in odd positions
|
24
|
+
i = 12
|
25
|
+
br = barcode.reverse
|
26
|
+
br.each_char do |c|
|
27
|
+
digit = c.to_i
|
28
|
+
if i.modulo(2) == 0 then
|
29
|
+
se = se + digit
|
30
|
+
else
|
31
|
+
so = so + digit
|
32
|
+
end
|
33
|
+
i = i - 1
|
34
|
+
end
|
35
|
+
se = se * 3
|
36
|
+
ss = se + so
|
37
|
+
mof10 = ss - ss.modulo(10) + 10
|
38
|
+
r = mof10 - ss
|
39
|
+
if r == 10 then
|
40
|
+
r = 0
|
41
|
+
end
|
42
|
+
r.to_s
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
data/pabarcode.gemspec
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{pabarcode}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Petros Amiridis"]
|
9
|
+
s.date = %q{2009-12-30}
|
10
|
+
s.description = %q{Helper classes for working with various barcode types}
|
11
|
+
s.email = %q{petros@amiridis.net}
|
12
|
+
s.extra_rdoc_files = ["README.rdoc", "lib/pabarcode.rb"]
|
13
|
+
s.files = ["README.rdoc", "Rakefile", "barcode_test.rb", "lib/pabarcode.rb", "pabarcode.gemspec"]
|
14
|
+
s.homepage = %q{http://github.com/amiridis/pabarcode}
|
15
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "PAbarcode", "--main", "README.rdoc"]
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.rubyforge_project = %q{pabarcode}
|
18
|
+
s.rubygems_version = %q{1.3.5}
|
19
|
+
s.summary = %q{Helper classes for working with various barcode types}
|
20
|
+
|
21
|
+
if s.respond_to? :specification_version then
|
22
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
23
|
+
s.specification_version = 3
|
24
|
+
|
25
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
26
|
+
else
|
27
|
+
end
|
28
|
+
else
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pabarcode
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Petros Amiridis
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-30 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Helper classes for working with various barcode types
|
17
|
+
email: petros@amiridis.net
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
- lib/pabarcode.rb
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- barcode_test.rb
|
29
|
+
- lib/pabarcode.rb
|
30
|
+
- pabarcode.gemspec
|
31
|
+
has_rdoc: true
|
32
|
+
homepage: http://github.com/amiridis/pabarcode
|
33
|
+
licenses: []
|
34
|
+
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --line-numbers
|
38
|
+
- --inline-source
|
39
|
+
- --title
|
40
|
+
- PAbarcode
|
41
|
+
- --main
|
42
|
+
- README.rdoc
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "1.2"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: pabarcode
|
60
|
+
rubygems_version: 1.3.5
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Helper classes for working with various barcode types
|
64
|
+
test_files: []
|
65
|
+
|