salsify-gtin 0.1.0 → 0.2.0

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
  SHA256:
3
- metadata.gz: 0a8c676f5728c7d682a37f142e9c33bb315d85513eb1a5638fe51a5c072c2e0a
4
- data.tar.gz: ffb738ff12692ab87efe8763e1869eeafcdde038d22942026f3c546bd585e252
3
+ metadata.gz: 5f279583cc76509f46898df34d5b66a27a7454db60d5f9f7fe8f05e161afaf51
4
+ data.tar.gz: b730b522cc2d9defbf1abbfc10d77658bc7a95dea0806f4481310dae2bca8ced
5
5
  SHA512:
6
- metadata.gz: '09f94b7bac8f4c3bba93150bb2dcf4f09550578ce1556713b0ba835678b3706aadb5529f74228b16833817c620cdc57d134a5d0a7fa8d86c43f66b3ae793b707'
7
- data.tar.gz: 7f2bc78e96b9cd8e9680eb5ecd890706394123571ea10da790003514de77eb808b9fddf6d9c5e531805b639fc48f5a05e49fdbd8085fec070b0402d86f3a4021
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
- [/(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
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
@@ -1,3 +1,3 @@
1
1
  module GTIN
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
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.1.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-01-30 00:00:00.000000000 Z
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"