salsify-gtin 0.1.0 → 0.2.0
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/.circleci/config.yml +33 -0
- data/lib/gtin/gtin.rb +12 -10
- data/lib/gtin/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f279583cc76509f46898df34d5b66a27a7454db60d5f9f7fe8f05e161afaf51
|
4
|
+
data.tar.gz: b730b522cc2d9defbf1abbfc10d77658bc7a95dea0806f4481310dae2bca8ced
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f29318ae9ae3fccc96a401a19f7b6125a2531dbeec40e6fcaa993f7e6c25a1fc38835c09809479108b9e961fccfa01b633d6a7a55043ed57e0c5c856f570d7e
|
7
|
+
data.tar.gz: 10a357e7e16c526bd6278625699c73b035afdbc4542d605dc5fa371b48e11a68774a3799626740799978d1d6e803c47d37befea1e28e65da4888e21d5fbeb1e7
|
@@ -0,0 +1,33 @@
|
|
1
|
+
version: 2
|
2
|
+
jobs:
|
3
|
+
build:
|
4
|
+
docker:
|
5
|
+
- image: salsify/ruby_ci:2.5.1
|
6
|
+
working_directory: ~/gtin
|
7
|
+
steps:
|
8
|
+
- checkout
|
9
|
+
- restore_cache:
|
10
|
+
keys:
|
11
|
+
- v1-gems-ruby-2.5.1-{{ checksum "salsify-jira.gemspec" }}-{{ checksum "Gemfile.lock" }}
|
12
|
+
- v1-gems-ruby-2.5.1-
|
13
|
+
- run:
|
14
|
+
name: Install Gems
|
15
|
+
command: |
|
16
|
+
if ! bundle check --path=vendor/bundle; then
|
17
|
+
bundle install --path=vendor/bundle --jobs=4 --retry=3
|
18
|
+
bundle clean
|
19
|
+
fi
|
20
|
+
- save_cache:
|
21
|
+
key: v1-gems-ruby-2.5.1-{{ checksum "salsify-jira.gemspec" }}-{{ checksum "Gemfile.lock" }}
|
22
|
+
paths:
|
23
|
+
- "vendor/bundle"
|
24
|
+
- "gemfiles/vendor"
|
25
|
+
- run:
|
26
|
+
name: Run Rubocop
|
27
|
+
command: bundle exec rubocop
|
28
|
+
- run:
|
29
|
+
name: Run Tests
|
30
|
+
command: |
|
31
|
+
bundle exec rspec --format RspecJunitFormatter --out $CIRCLE_TEST_REPORTS/rspec/junit.xml --format progress spec
|
32
|
+
- store_test_results:
|
33
|
+
path: 'test-results'
|
data/lib/gtin/gtin.rb
CHANGED
@@ -9,18 +9,16 @@ module GTIN
|
|
9
9
|
IssnConverter = Converter.new(:standardize_issn8, :compute_checksum_issn8)
|
10
10
|
|
11
11
|
CONVERTER_MAP = {
|
12
|
-
[
|
13
|
-
[
|
14
|
-
[
|
15
|
-
[
|
16
|
-
[
|
17
|
-
[
|
18
|
-
[
|
19
|
-
[
|
12
|
+
[/^(GTIN|EAN)(-?8)?$/i, 8] => GtinConverter,
|
13
|
+
[/^(GTIN|EAN)(-?12)?$/i, 12] => GtinConverter,
|
14
|
+
[/^(GTIN|EAN|ISBN|ISSN)(-?13)?$/i, 13] => GtinConverter,
|
15
|
+
[/^(GTIN|EAN)(-?14)?$/i, 14] => GtinConverter,
|
16
|
+
[/^UPC(-?A)?$/i, 12] => GtinConverter,
|
17
|
+
[/^UPC(-?E)?$/i, 7] => UpcEConverter,
|
18
|
+
[/^ISBN(-?10)?$/i, 10] => IsbnConverter,
|
19
|
+
[/^ISSN(-?8)?$/i, 8] => IssnConverter
|
20
20
|
}.freeze
|
21
21
|
|
22
|
-
GTIN_COMPATIBLE_ID_TYPES = %w(UPC GTIN EAN ISSN ISBN).freeze
|
23
|
-
|
24
22
|
GtinValidationError = Class.new(StandardError)
|
25
23
|
|
26
24
|
# raises GtinValidationError if the provided value has an invalid checksum
|
@@ -113,4 +111,8 @@ module GTIN
|
|
113
111
|
def compute_checksum_upce(unchecked_upce)
|
114
112
|
standardize('UPC', unchecked_upce + '0', validate_checksum: false)[-1]
|
115
113
|
end
|
114
|
+
|
115
|
+
def gtin_compatible?(id_type)
|
116
|
+
CONVERTER_MAP.keys.map(&:first).any? { |r| r.match?(id_type) }
|
117
|
+
end
|
116
118
|
end
|
data/lib/gtin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: salsify-gtin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Salsify, Inc
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -103,6 +103,7 @@ executables:
|
|
103
103
|
extensions: []
|
104
104
|
extra_rdoc_files: []
|
105
105
|
files:
|
106
|
+
- ".circleci/config.yml"
|
106
107
|
- ".gitignore"
|
107
108
|
- ".init"
|
108
109
|
- ".overcommit.yml"
|