unidom-article_number 2.0.2 → 2.1
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 848207ee1c89545ac553f01f85c8e7ef923b58c3
|
4
|
+
data.tar.gz: 5021a99800b1e57a4160a548e7a7f883f585df81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44d5e55dbdc6fcf78ef9ddfc5720b7de914c88c9380c2c3ba1c0dd434de87549c80d4aee70fe935fcc0740089886c2999e99c92431d25e15ec01cde35dc7f252
|
7
|
+
data.tar.gz: cabbc1e5f6818d6c9b0ecf6d5a456d2bf341ef3fe4f78fc7a12533db5e14279bed4bd9c28cb51a8b81584d9b81f4238731730962c32531bf5f6ae3d5f9b64e3b
|
data/README.md
CHANGED
@@ -82,3 +82,13 @@ The As EAN-13 Marked concern do the following tasks for the includer automatical
|
|
82
82
|
The As EAN-8 Marked concern do the following tasks for the includer automatically:
|
83
83
|
1. Include the As Marked concern
|
84
84
|
2. Define the has_many :ean8_barcodes macro as: ``has_many :ean8_barcodes, through: :markings, source: :barcode, source_type: 'Unidom::ArticleNumber::Ean8Barcode'``
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
## Validator
|
89
|
+
|
90
|
+
### Vehicle Identification Number validator
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
validates :vin, presence: true, 'unidom/article_number/vehicle_identification_number': true
|
94
|
+
```
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# https://en.wikipedia.org/wiki/Vehicle_identification_number#Check-digit_calculation
|
2
|
+
# GB 16735-2004
|
3
|
+
|
4
|
+
class Unidom::ArticleNumber::VehicleIdentificationNumberValidator < ActiveModel::EachValidator
|
5
|
+
|
6
|
+
WEIGHTS = '8765432X098765432'.freeze
|
7
|
+
TRANSLITERATION = '0123456789.ABCDEFGH..JKLMN.P.R..STUVWXYZ'.freeze
|
8
|
+
CHECK_DIGITS = '0123456789X'.freeze
|
9
|
+
|
10
|
+
def validate_each(record, attribute, value)
|
11
|
+
value = value.to_s.upcase
|
12
|
+
record.errors[attribute] << (options[:message]||'is invalid') unless check_digit(value)==value[8]
|
13
|
+
end
|
14
|
+
|
15
|
+
def check_digit(value)
|
16
|
+
checksum = 0
|
17
|
+
value.chars.each_with_index do |char, index| checksum += self.class::TRANSLITERATION.index(char)%10*self.class::CHECK_DIGITS.index(self.class::WEIGHTS.at(index)) end
|
18
|
+
self.class::CHECK_DIGITS.at checksum%11
|
19
|
+
end
|
20
|
+
|
21
|
+
private :check_digit
|
22
|
+
|
23
|
+
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
<html>
|
3
3
|
<head>
|
4
4
|
<title>ArticleNumber</title>
|
5
|
-
<%= stylesheet_link_tag
|
5
|
+
<%= stylesheet_link_tag "unidom/article_number/application", media: "all" %>
|
6
6
|
<%= csrf_meta_tags %>
|
7
7
|
</head>
|
8
8
|
<body>
|
9
9
|
|
10
10
|
<%= yield %>
|
11
11
|
|
12
|
-
<%= javascript_include_tag 'article_number/application' %>
|
12
|
+
<%= javascript_include_tag 'unidom/article_number/application' %>
|
13
13
|
|
14
14
|
</body>
|
15
15
|
</html>
|
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: 2.
|
4
|
+
version: '2.1'
|
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-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: unidom-common
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- app/models/unidom/article_number/ean13_barcode.rb
|
53
53
|
- app/models/unidom/article_number/ean8_barcode.rb
|
54
54
|
- app/models/unidom/article_number/marking.rb
|
55
|
+
- app/validators/unidom/article_number/vehicle_identification_number_validator.rb
|
55
56
|
- app/views/layouts/unidom/article_number/application.html.erb
|
56
57
|
- config/routes.rb
|
57
58
|
- db/migrate/20020101000000_create_unidom_markings.rb
|