unidom-article_number 0.1

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: b29eca548ef0229205de8ac5451060bbc1debf3a
4
+ data.tar.gz: 5733a830ab8bea2c0abc1bf73ca74c8aeaa41684
5
+ SHA512:
6
+ metadata.gz: df46eddbdc235588c006436f6d00c09aa669cf787fab7b90f9a9e96d1bb5ab39876ee835e710261fdbb2971318c4e20180d347667ac92c73de4679d54ef9e7a9
7
+ data.tar.gz: 5221222bdb6e5a289d6422392bde2fe83ef04a0062bc66c5194880567ca616f0ebcd58dbaf2aa2a738fc5f0d22326706f27e07c341d59183b518f86eb5a54252
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Topbit Du
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,21 @@
1
+ # Unidom Article Number 物品编码领域模型引擎
2
+
3
+ [![License](https://img.shields.io/badge/license-MIT-green.svg)](http://opensource.org/licenses/MIT)
4
+
5
+ Unidom (UNIfied Domain Object Model) is a series of domain model engines. The Article Number domain model engine includes EAN-13, EAN-8, and IMEI models.
6
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。物品编码领域模型引擎包括EAN-13、EAN-8和IMEI的模型。
7
+
8
+ ## Usage in Gemfile:
9
+ ```ruby
10
+ gem 'unidom-article_number'
11
+ ```
12
+
13
+ ## Run the Database Migration:
14
+ ```shell
15
+ rake db:migrate
16
+ ```
17
+
18
+ ## Call the Model:
19
+ ```ruby
20
+ Unidom::ArticleNumber::Ean13Barcode.coded_as('1234567890123').valid_at.alive.first.markings
21
+ ```
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Unidom Article Number'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+ load 'rails/tasks/statistics.rake'
20
+
21
+
22
+
23
+ Bundler::GemHelper.install_tasks
24
+
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,2 @@
1
+ class Unidom::ArticleNumber::ApplicationController < ActionController::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ module Unidom::ArticleNumber::ApplicationHelper
2
+ end
@@ -0,0 +1,26 @@
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::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
@@ -0,0 +1,37 @@
1
+ # EAN-13 Barcode 是13位条形码。
2
+ # https://en.wikipedia.org/wiki/EAN-13
3
+ # https://en.wikipedia.org/wiki/International_Article_Number_(EAN)
4
+
5
+ class Unidom::ArticleNumber::Ean13Barcode < ActiveRecord::Base
6
+
7
+ RESTRICTED_DISTRIBUTION_GS1_PREFIXES = (('020'..'029').to_a + ('040'..'049').to_a + ('200'..'299').to_a).freeze
8
+
9
+ self.table_name = 'unidom_ean_13_barcodes'
10
+
11
+ #validates :code, presence: true, length: { is: self.columns_hash['code'].limit }, numericality: { only_integer: true }, uniqueness: true
12
+ validates :code, uniqueness: true, numericality: { only_integer: true }
13
+ validates :gs1_prefix, presence: true, length: { is: 3 }, numericality: { only_integer: true }
14
+ validates :company_number, presence: true, length: { is: 4 }, numericality: { only_integer: true }
15
+ validates :item_reference, presence: true, length: { is: 5 }, numericality: { only_integer: true }
16
+ validates :check_digit, presence: true, length: { is: 1 }, numericality: { only_integer: true }
17
+
18
+ has_many :markings, class_name: 'Unidom::ArticleNumber::Marking'
19
+
20
+ include ::Unidom::Common::ModelExtension
21
+
22
+ def code=(code)
23
+ code = code.to_s
24
+ write_attribute :code, code
25
+ if code.present?
26
+ write_attribute :gs1_prefix, code[0..2]
27
+ write_attribute :company_number, code[3..6]
28
+ write_attribute :item_reference, code[7..11]
29
+ write_attribute :check_digit, code[12]
30
+ end
31
+ end
32
+
33
+ def restricted_distribution?
34
+ self.class::RESTRICTED_DISTRIBUTION_GS1_PREFIXES.include? gs1_prefix
35
+ end
36
+
37
+ end
@@ -0,0 +1,15 @@
1
+ # Marking 是条码和物品的标记关系。
2
+
3
+ class Unidom::ArticleNumber::Marking < ActiveRecord::Base
4
+
5
+ self.table_name = 'unidom_markings'
6
+
7
+ belongs_to :barcode, polymorphic: true
8
+ belongs_to :marked, polymorphic: true
9
+ belongs_to :marker, polymorphic: true
10
+
11
+ scope :barcode_is, ->(barcode) { where barcode: barcode }
12
+ scope :marked_by, ->(marker) { where marker: marker }
13
+ scope :marked_is, ->(marked) { where marked: marked }
14
+
15
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>ArticleNumber</title>
5
+ <%= stylesheet_link_tag "article_number/application", media: "all" %>
6
+ <%= javascript_include_tag "article_number/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,2 @@
1
+ Unidom::ArticleNumber::Engine.routes.draw do
2
+ end
@@ -0,0 +1,30 @@
1
+ class CreateUnidomMarkings < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_markings, id: :uuid do |t|
6
+
7
+ t.references :barcode, type: :uuid, null: false,
8
+ polymorphic: { null: false, default: '', limit: 200 }
9
+ t.references :marked, type: :uuid, null: false,
10
+ polymorphic: { null: false, default: '', limit: 200 }
11
+ t.references :marker, type: :uuid, null: false,
12
+ polymorphic: { null: false, default: '', limit: 200 }
13
+
14
+ t.column :state, 'char(1)', null: false, default: 'C'
15
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
16
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
17
+ t.boolean :defunct, null: false, default: false
18
+ t.jsonb :notation, null: false, default: {}
19
+
20
+ t.timestamps null: false
21
+
22
+ end
23
+
24
+ add_index :unidom_markings, :barcode_id
25
+ add_index :unidom_markings, :marked_id
26
+ add_index :unidom_markings, :marker_id
27
+
28
+ end
29
+
30
+ end
@@ -0,0 +1,27 @@
1
+ class CreateUnidomEan13Barcodes < ActiveRecord::Migration
2
+
3
+ def change
4
+
5
+ create_table :unidom_ean_13_barcodes, id: :uuid do |t|
6
+
7
+ t.column :code, 'char(13)', null: false, default: '0'*13
8
+ t.column :gs1_prefix, 'char(3)', null: false, default: '0'*3
9
+ t.string :company_number, null: false, default: '0'*3, limit: 8
10
+ t.string :item_reference, null: false, default: '0'*2, limit: 6
11
+ t.column :check_digit, 'char(1)', null: false, default: '0'
12
+
13
+ t.column :state, 'char(1)', null: false, default: 'C'
14
+ t.datetime :opened_at, null: false, default: ::Time.utc(1970)
15
+ t.datetime :closed_at, null: false, default: ::Time.utc(3000)
16
+ t.boolean :defunct, null: false, default: false
17
+ t.jsonb :notation, null: false, default: {}
18
+
19
+ t.timestamps null: false
20
+
21
+ end
22
+
23
+ add_index :unidom_ean_13_barcodes, :code, unique: true
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,24 @@
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
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :article_number do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,6 @@
1
+ require 'unidom/article_number/engine'
2
+
3
+ module Unidom
4
+ module ArticleNumber
5
+ end
6
+ end
@@ -0,0 +1,15 @@
1
+ module Unidom
2
+ module ArticleNumber
3
+
4
+ class Engine < ::Rails::Engine
5
+
6
+ isolate_namespace ::Unidom::ArticleNumber
7
+
8
+ initializer :append_migrations do |app|
9
+ config.paths['db/migrate'].expanded.each { |expanded_path| app.config.paths['db/migrate'] << expanded_path } unless app.root.to_s.match root.to_s
10
+ end
11
+
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Unidom
2
+ module ArticleNumber
3
+ VERSION = '0.1'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: unidom-article_number
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Topbit Du
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: unidom-common
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.2'
27
+ description: Unidom (UNIfied Domain Object Model) is a series of domain model engines.
28
+ The Article Number domain model engine includes EAN-13, EAN-8, and IMEI models.
29
+ Unidom (统一领域对象模型)是一系列的领域模型引擎。物品编码领域模型引擎包括EAN-13、EAN-8和IMEI的模型。
30
+ email:
31
+ - topbit.du@gmail.com
32
+ executables: []
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - MIT-LICENSE
37
+ - README.md
38
+ - Rakefile
39
+ - app/assets/javascripts/unidom/article_number/application.js
40
+ - app/assets/stylesheets/unidom/article_number/application.css
41
+ - app/controllers/unidom/article_number/application_controller.rb
42
+ - app/helpers/unidom/article_number/application_helper.rb
43
+ - app/models/unidom/article_number/code_128_barcode.rb
44
+ - app/models/unidom/article_number/ean_13_barcode.rb
45
+ - app/models/unidom/article_number/marking.rb
46
+ - app/views/layouts/unidom/article_number/application.html.erb
47
+ - config/routes.rb
48
+ - db/migrate/20020101000000_create_unidom_markings.rb
49
+ - db/migrate/20020102000000_create_unidom_ean_13_barcodes.rb
50
+ - db/migrate/20020111000000_create_unidom_code_128_barcodes.rb
51
+ - lib/tasks/article_number_tasks.rake
52
+ - lib/unidom/article_number.rb
53
+ - lib/unidom/article_number/engine.rb
54
+ - lib/unidom/article_number/version.rb
55
+ homepage: https://github.com/topbitdu/unidom-article_number
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.4.5.1
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: The Article Number domain model engine includes EAN-13, EAN-8, and IMEI models.
79
+ test_files: []