unidom-article_number 0.2 → 0.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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/models/unidom/article_number/concerns/code128_barcode.rb +31 -0
- data/app/models/unidom/article_number/{ean_13_barcode.rb → ean13_barcode.rb} +0 -1
- data/app/models/unidom/article_number/ean8_barcode.rb +32 -0
- data/db/migrate/20020103000000_create_unidom_ean_8_barcodes.rb +26 -0
- data/lib/unidom/article_number/version.rb +1 -1
- metadata +8 -7
- data/app/models/unidom/article_number/code_128_barcode.rb +0 -26
- data/db/migrate/20020111000000_create_unidom_code_128_barcodes.rb +0 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 31a017927192ed39cd495960a2c81cdb8615f1ab
|
|
4
|
+
data.tar.gz: cd821c0834fe5cec1b896d160ecbcd640fe7fe29
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5907f7e6751d1b3c926d25a20f610f537978a30b771c179b8b67fd8231ddd56ad94d2252be8f749bf18e16572101c809cbd13e0195b1e84598938f08445b04cf
|
|
7
|
+
data.tar.gz: 65bcdc1983891228b7f48a87824f7c78801af231582a510b754576d4aa787e3b8826dcf106a3d17bc21a6714c12641cebdb7355dfb322c4c441beef65c5a47e7
|
data/README.md
CHANGED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Code 128 条形码是高密度条形码符号。
|
|
2
|
+
# https://en.wikipedia.org/wiki/Code_128
|
|
3
|
+
# Code 128 A 条形码 code set: ASCII characters 00 to 95 (0-9, A-Z and control codes), special characters, and FNC 1-4.
|
|
4
|
+
# Code 128 B 条形码 code set: ASCII characters 32 to 127 (0-9, A-Z, a-z), special characters, and FNC 1-4.
|
|
5
|
+
# Code 128 C 条形码 code set: 00-99 (encodes each two digits with one code) and FNC1.
|
|
6
|
+
|
|
7
|
+
module Unidom::ArticleNumber::Concerns::Code128Barcode
|
|
8
|
+
|
|
9
|
+
extend ActiveSupport::Concern
|
|
10
|
+
|
|
11
|
+
self.included do |includer|
|
|
12
|
+
|
|
13
|
+
validates :code, uniqueness: true
|
|
14
|
+
validates :code, numericality: { only_integer: true }, if: Proc.new { |barcode| 'C'==barcode.code_set_code }
|
|
15
|
+
|
|
16
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
17
|
+
|
|
18
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
19
|
+
|
|
20
|
+
#def weighted_modulo_103_checksum(codes)
|
|
21
|
+
# sum = 103
|
|
22
|
+
# codes.each_with_index do |char, index| sum += (char.unpack('C').first-32)*(index+1) end
|
|
23
|
+
# sum%103
|
|
24
|
+
#end
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
module ClassMethods
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -8,7 +8,6 @@ class Unidom::ArticleNumber::Ean13Barcode < ActiveRecord::Base
|
|
|
8
8
|
|
|
9
9
|
self.table_name = 'unidom_ean_13_barcodes'
|
|
10
10
|
|
|
11
|
-
#validates :code, presence: true, length: { is: self.columns_hash['code'].limit }, numericality: { only_integer: true }, uniqueness: true
|
|
12
11
|
validates :code, uniqueness: true, numericality: { only_integer: true }
|
|
13
12
|
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
14
13
|
validates :company_number, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# EAN-8 Barcode 是8位条形码。
|
|
2
|
+
# https://en.wikipedia.org/wiki/EAN-8
|
|
3
|
+
class Unidom::ArticleNumber::Ean8Barcode < ActiveRecord::Base
|
|
4
|
+
|
|
5
|
+
RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
|
|
6
|
+
|
|
7
|
+
self.table_name = 'unidom_ean_8_barcodes'
|
|
8
|
+
|
|
9
|
+
validates :code, uniqueness: true, numericality: { only_integer: true }
|
|
10
|
+
validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
|
|
11
|
+
validates :item_reference, presence: true, length: { is: 4 }, numericality: { only_integer: true }
|
|
12
|
+
validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
|
|
13
|
+
|
|
14
|
+
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
15
|
+
|
|
16
|
+
include Unidom::Common::Concerns::ModelExtension
|
|
17
|
+
|
|
18
|
+
def code=(code)
|
|
19
|
+
code = code.to_s
|
|
20
|
+
write_attribute :code, code
|
|
21
|
+
if code.present?
|
|
22
|
+
write_attribute :gs1_prefix, code[0..2]
|
|
23
|
+
write_attribute :item_reference, code[3..6]
|
|
24
|
+
write_attribute :check_digit, code[7]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def restricted_distribution?
|
|
29
|
+
self.class::RESTRICTED_DISTRIBUTION_GS1_PREFIXES.include? gs1_prefix
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
class CreateUnidomEan8Barcodes < ActiveRecord::Migration
|
|
2
|
+
|
|
3
|
+
def change
|
|
4
|
+
|
|
5
|
+
create_table :unidom_ean_8_barcodes, id: :uuid do |t|
|
|
6
|
+
|
|
7
|
+
t.column :code, 'char(8)', null: false, default: '0'*8
|
|
8
|
+
t.column :gs1_prefix, 'char(3)', null: false, default: '0'*3
|
|
9
|
+
t.column :item_reference, 'char(4)', null: false, default: '0'*4
|
|
10
|
+
t.column :check_digit, 'char(1)', null: false, default: '0'
|
|
11
|
+
|
|
12
|
+
t.column :state, 'char(1)', null: false, default: 'C'
|
|
13
|
+
t.datetime :opened_at, null: false, default: ::Time.utc(1970)
|
|
14
|
+
t.datetime :closed_at, null: false, default: ::Time.utc(3000)
|
|
15
|
+
t.boolean :defunct, null: false, default: false
|
|
16
|
+
t.jsonb :notation, null: false, default: {}
|
|
17
|
+
|
|
18
|
+
t.timestamps null: false
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
add_index :unidom_ean_8_barcodes, :code, unique: true
|
|
23
|
+
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: unidom-article_number
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: '0.
|
|
4
|
+
version: '0.3'
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Topbit Du
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2016-
|
|
11
|
+
date: 2016-03-13 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: unidom-common
|
|
@@ -16,14 +16,14 @@ dependencies:
|
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '0.
|
|
19
|
+
version: '0.4'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '0.
|
|
26
|
+
version: '0.4'
|
|
27
27
|
description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
|
|
28
28
|
The Article Number domain model engine includes EAN-13, EAN-8, and IMEI models.
|
|
29
29
|
Unidom (统一领域对象模型)是一系列的领域模型引擎。物品编码领域模型引擎包括EAN-13、EAN-8和IMEI的模型。
|
|
@@ -40,14 +40,15 @@ files:
|
|
|
40
40
|
- app/assets/stylesheets/unidom/article_number/application.css
|
|
41
41
|
- app/controllers/unidom/article_number/application_controller.rb
|
|
42
42
|
- app/helpers/unidom/article_number/application_helper.rb
|
|
43
|
-
- app/models/unidom/article_number/
|
|
44
|
-
- app/models/unidom/article_number/
|
|
43
|
+
- app/models/unidom/article_number/concerns/code128_barcode.rb
|
|
44
|
+
- app/models/unidom/article_number/ean13_barcode.rb
|
|
45
|
+
- app/models/unidom/article_number/ean8_barcode.rb
|
|
45
46
|
- app/models/unidom/article_number/marking.rb
|
|
46
47
|
- app/views/layouts/unidom/article_number/application.html.erb
|
|
47
48
|
- config/routes.rb
|
|
48
49
|
- db/migrate/20020101000000_create_unidom_markings.rb
|
|
49
50
|
- db/migrate/20020102000000_create_unidom_ean_13_barcodes.rb
|
|
50
|
-
- db/migrate/
|
|
51
|
+
- db/migrate/20020103000000_create_unidom_ean_8_barcodes.rb
|
|
51
52
|
- lib/tasks/article_number_tasks.rake
|
|
52
53
|
- lib/unidom/article_number.rb
|
|
53
54
|
- lib/unidom/article_number/engine.rb
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
# Code 128 条形码是高密度条形码符号。
|
|
2
|
-
# https://en.wikipedia.org/wiki/Code_128
|
|
3
|
-
# Code 128 A 条形码 code set: ASCII characters 00 to 95 (0-9, A-Z and control codes), special characters, and FNC 1-4.
|
|
4
|
-
# Code 128 B 条形码 code set: ASCII characters 32 to 127 (0-9, A-Z, a-z), special characters, and FNC 1-4.
|
|
5
|
-
# Code 128 C 条形码 code set: 00-99 (encodes each two digits with one code) and FNC1.
|
|
6
|
-
|
|
7
|
-
class Unidom::ArticleNumber::Code128Barcode < ::ActiveRecord::Base
|
|
8
|
-
|
|
9
|
-
self.table_name = 'unidom_code_128_barcodes'
|
|
10
|
-
|
|
11
|
-
#validates :code, presence: true, length: { is: self.columns_hash['code'].limit }, uniqueness: true
|
|
12
|
-
validates :code, uniqueness: true
|
|
13
|
-
validates :code, numericality: { only_integer: true }, if: Proc.new { |barcode| 'C'==barcode.code_set_code }
|
|
14
|
-
|
|
15
|
-
has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
|
|
16
|
-
|
|
17
|
-
include Unidom::Common::Concerns::ModelExtension
|
|
18
|
-
|
|
19
|
-
def weighted_modulo_103_checksum(codes)
|
|
20
|
-
sum = 103
|
|
21
|
-
codes.each_with_index do |char, index| sum += (char.unpack('C').first-32)*(index+1) end
|
|
22
|
-
sum%103
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
end
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
class CreateUnidomCode128Barcodes < ActiveRecord::Migration
|
|
2
|
-
|
|
3
|
-
def change
|
|
4
|
-
|
|
5
|
-
create_table :unidom_code_128_barcodes, id: :uuid do |t|
|
|
6
|
-
|
|
7
|
-
t.column :code, 'char(20)', null: false, default: '0'*20
|
|
8
|
-
t.column :code_set_code, 'char(1)', null: false, default: 'A'
|
|
9
|
-
|
|
10
|
-
t.column :state, 'char(1)', null: false, default: 'C'
|
|
11
|
-
t.datetime :opened_at, null: false, default: ::Time.utc(1970)
|
|
12
|
-
t.datetime :closed_at, null: false, default: ::Time.utc(3000)
|
|
13
|
-
t.boolean :defunct, null: false, default: false
|
|
14
|
-
t.jsonb :notation, null: false, default: {}
|
|
15
|
-
|
|
16
|
-
t.timestamps null: false
|
|
17
|
-
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
add_index :unidom_code_128_barcodes, :code, unique: true
|
|
21
|
-
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
end
|