img2zpl 1.0.0 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5dc00b95a89a63d7e2464f9564224043d229702fa2ee34f867f87588c6ff7446
4
- data.tar.gz: 32e08dbe2a982507a56d3c71c421bd396351219d44b7e0394eccb50a172048e4
3
+ metadata.gz: 85f87b66f8684ac6b08e864c77dfadeb5fe4af4d5e123c51936f16038b302759
4
+ data.tar.gz: 71c21dd57dcb10359496f5cb5fb77b82ca95009d3aaf849076c5cceaf57de0f9
5
5
  SHA512:
6
- metadata.gz: 4f0a368e1c0caad2bfd9d6ccba1e35104cf3e17a80b72aec71aa58df88f8ede49b63a8addc53c21dc9d82ea6c9bc047bc0642da73d4df18fe90e8cf1891b99f0
7
- data.tar.gz: 105c15388445dfea07ed5e0b40d5e7f4b4739cb52661ad9f12d68641180d49904bb737de78f5cd657247d5e331aea043fafb8b76948aad27a43371b2eee77eea
6
+ metadata.gz: 408bc5777a3602c337f4c5e3385e0b147fa4393af8050733a8205f63e32a4ea2bda9a47caec85beb1e713d98c9ccfb7040b5b6dde6387d0c8d784281ca0faa1b
7
+ data.tar.gz: aefd91acfeb404bde3196c53d956a685bbea68662e62428dea36f67a9d5ce22aaa87bb89d1b96bc1fcb34285a094f7798f8c418eb45fa9b08b9e2d43b9995b86
@@ -0,0 +1,42 @@
1
+ name: "Lint and Test"
2
+ on:
3
+ push:
4
+ branches: [ "master" ]
5
+ pull_request:
6
+ merge_group:
7
+ workflow_dispatch:
8
+
9
+ jobs:
10
+
11
+ rubocop:
12
+ name: Lint Ruby files
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - name: Checkout code
16
+ uses: actions/checkout@v4
17
+
18
+ - name: Install Ruby and gems
19
+ uses: ruby/setup-ruby@v1
20
+ with:
21
+ bundler-cache: true
22
+
23
+ - name: Run Rubocop
24
+ run: bin/rubocop --format simple --format github
25
+
26
+ rspec:
27
+ name: Run RSpec
28
+ runs-on: ubuntu-latest
29
+ steps:
30
+ - name: Checkout code
31
+ uses: actions/checkout@v4
32
+
33
+ - name: Install ImageMagick
34
+ run: sudo apt-get update && sudo apt-get install -y imagemagick
35
+
36
+ - name: Install Ruby and gems
37
+ uses: ruby/setup-ruby@v1
38
+ with:
39
+ bundler-cache: true
40
+
41
+ - name: Run tests
42
+ run: bin/rspec
data/.gitignore CHANGED
@@ -48,3 +48,5 @@ Gemfile.lock
48
48
 
49
49
  # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
50
  .rvmrc
51
+
52
+ .ruby-lsp/
data/.rubocop.yml ADDED
@@ -0,0 +1,41 @@
1
+ require:
2
+ - standard
3
+ plugins:
4
+ - rubocop-rspec
5
+ - rubocop-performance
6
+
7
+ inherit_gem:
8
+ standard: config/base.yml
9
+
10
+ AllCops:
11
+ NewCops: enable
12
+ StringLiteralsFrozenByDefault: false
13
+ Exclude:
14
+ - bin/**/*
15
+ - vendor/**/*
16
+
17
+ Layout/IndentationStyle:
18
+ EnforcedStyle: tabs
19
+
20
+ Layout/SpaceInsideHashLiteralBraces:
21
+ EnforcedStyle: space
22
+
23
+ Layout/EmptyLinesAroundClassBody:
24
+ EnforcedStyle: empty_lines
25
+
26
+ Layout/EmptyLinesAroundModuleBody:
27
+ EnforcedStyle: empty_lines
28
+
29
+ Layout/IndentationWidth:
30
+ Width: 1
31
+
32
+ RSpec/ExampleLength:
33
+ Enabled: true
34
+ Max: 10
35
+
36
+ RSpec/MultipleExpectations:
37
+ Enabled: true
38
+ Max: 3
39
+
40
+ Style/NilComparison:
41
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.1
data/CHANGELOG.md CHANGED
@@ -1,7 +1,11 @@
1
- ### v1.0.x (next)
1
+ ### v1.0.2 (next)
2
2
 
3
3
  * Your contribution here
4
4
 
5
+ ### v1.0.1 (2019/11/05)
6
+
7
+ * [#5](https://github.com/mtking2/img2zpl/pull/5): Fix artifact bug & improve compression - [@mtking2](https://github.com/mtking2).
8
+
5
9
  ### v1.0.0 (2019/10/31)
6
10
 
7
11
  * [#4](https://github.com/mtking2/img2zpl/pull/4): Add ability to invert images - [@mtking2](https://github.com/mtking2).
data/CONTRIBUTING.md CHANGED
@@ -6,7 +6,7 @@
6
6
  git clone git@github.com:<your-username>/img2zpl.git
7
7
  cd img2zpl
8
8
  git remote add upstream git@github.com:mtking2/img2zpl.git
9
- bundle install
9
+ bin/setup
10
10
  ```
11
11
 
12
12
  Then check out a working branch:
data/Gemfile CHANGED
@@ -1,9 +1,11 @@
1
- source 'https://rubygems.org'
1
+ source "https://rubygems.org"
2
2
 
3
3
  group :development, :test do
4
- gem 'byebug'
5
- gem 'pry'
6
- gem 'pry-nav'
4
+ gem "debug"
5
+ gem "rubocop", require: false
6
+ gem "rubocop-rspec", require: false
7
+ gem "rubocop-performance", require: false
8
+ gem "standard", "~> 1.49.0", require: false
7
9
  end
8
10
 
9
11
  gemspec
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # img2zpl
2
2
 
3
- [![gem](https://img.shields.io/gem/v/img2zpl)](https://rubygems.org/gems/img2zpl)
3
+ [![gem](https://img.shields.io/gem/v/img2zpl?color=orange)](https://rubygems.org/gems/img2zpl)
4
4
  [![downloads](https://img.shields.io/gem/dt/img2zpl?color=brightgreen)](https://rubygems.org/gems/img2zpl)
5
5
 
6
6
  Ruby library to convert images to usable &amp; printable ZPL code
@@ -33,10 +33,11 @@ The `Img2Zpl::Image` class inherits from the `MiniMagick::Image` class provied b
33
33
 
34
34
  **Example**:
35
35
  ```ruby
36
- img = Img2Zpl::Image.open('foo.jpg')
36
+ img = Img2Zpl::Image.open('foo.png')
37
37
 
38
- img.resize '100x100'
38
+ img.flatten
39
39
  img.trim
40
+ img.resize '100x100'
40
41
 
41
42
  zpl = img.to_zpl
42
43
  ```
data/Rakefile CHANGED
@@ -1,14 +1,14 @@
1
- require 'rubygems'
2
- require 'bundler'
3
- require 'bundler/gem_tasks'
1
+ require "rubygems"
2
+ require "bundler"
3
+ require "bundler/gem_tasks"
4
4
 
5
5
  Bundler.setup :default, :development
6
6
 
7
- require 'rspec/core'
8
- require 'rspec/core/rake_task'
7
+ require "rspec/core"
8
+ require "rspec/core/rake_task"
9
9
 
10
10
  RSpec::Core::RakeTask.new(:spec) do |spec|
11
- spec.pattern = FileList['spec/**/*_spec.rb']
11
+ spec.pattern = FileList["spec/**/*_spec.rb"]
12
12
  end
13
13
 
14
14
  task default: %i[spec]
data/bin/bundle ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'bundle' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "rubygems"
12
+
13
+ m = Module.new do
14
+ module_function
15
+
16
+ def invoked_as_script?
17
+ File.expand_path($0) == File.expand_path(__FILE__)
18
+ end
19
+
20
+ def env_var_version
21
+ ENV["BUNDLER_VERSION"]
22
+ end
23
+
24
+ def cli_arg_version
25
+ return unless invoked_as_script? # don't want to hijack other binstubs
26
+ return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
27
+ bundler_version = nil
28
+ update_index = nil
29
+ ARGV.each_with_index do |a, i|
30
+ if update_index && update_index.succ == i && a.match?(Gem::Version::ANCHORED_VERSION_PATTERN)
31
+ bundler_version = a
32
+ end
33
+ next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
34
+ bundler_version = $1
35
+ update_index = i
36
+ end
37
+ bundler_version
38
+ end
39
+
40
+ def gemfile
41
+ gemfile = ENV["BUNDLE_GEMFILE"]
42
+ return gemfile if gemfile && !gemfile.empty?
43
+
44
+ File.expand_path("../Gemfile", __dir__)
45
+ end
46
+
47
+ def lockfile
48
+ lockfile =
49
+ case File.basename(gemfile)
50
+ when "gems.rb" then gemfile.sub(/\.rb$/, ".locked")
51
+ else "#{gemfile}.lock"
52
+ end
53
+ File.expand_path(lockfile)
54
+ end
55
+
56
+ def lockfile_version
57
+ return unless File.file?(lockfile)
58
+ lockfile_contents = File.read(lockfile)
59
+ return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
60
+ Regexp.last_match(1)
61
+ end
62
+
63
+ def bundler_requirement
64
+ @bundler_requirement ||=
65
+ env_var_version ||
66
+ cli_arg_version ||
67
+ bundler_requirement_for(lockfile_version)
68
+ end
69
+
70
+ def bundler_requirement_for(version)
71
+ return "#{Gem::Requirement.default}.a" unless version
72
+
73
+ bundler_gem_version = Gem::Version.new(version)
74
+
75
+ bundler_gem_version.approximate_recommendation
76
+ end
77
+
78
+ def load_bundler!
79
+ ENV["BUNDLE_GEMFILE"] ||= gemfile
80
+
81
+ activate_bundler
82
+ end
83
+
84
+ def activate_bundler
85
+ gem_error = activation_error_handling do
86
+ gem "bundler", bundler_requirement
87
+ end
88
+ return if gem_error.nil?
89
+ require_error = activation_error_handling do
90
+ require "bundler/version"
91
+ end
92
+ return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
93
+ warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
94
+ exit 42
95
+ end
96
+
97
+ def activation_error_handling
98
+ yield
99
+ nil
100
+ rescue StandardError, LoadError => e
101
+ e
102
+ end
103
+ end
104
+
105
+ m.load_bundler!
106
+
107
+ if m.invoked_as_script?
108
+ load Gem.bin_path("bundler", "bundle")
109
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "img2zpl"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rspec ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rspec' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
12
+
13
+ bundle_binstub = File.expand_path("bundle", __dir__)
14
+
15
+ if File.file?(bundle_binstub)
16
+ if File.read(bundle_binstub, 300).include?("This file was generated by Bundler")
17
+ load(bundle_binstub)
18
+ else
19
+ abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
20
+ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
21
+ end
22
+ end
23
+
24
+ require "rubygems"
25
+ require "bundler/setup"
26
+
27
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/img2zpl.gemspec CHANGED
@@ -1,23 +1,21 @@
1
- # coding: utf-8
2
- $LOAD_PATH.push File.expand_path('lib', __dir__)
3
- require 'img2zpl/version'
1
+ $LOAD_PATH.push File.expand_path("lib", __dir__)
2
+ require "img2zpl/version"
4
3
 
5
4
  Gem::Specification.new do |spec|
6
- spec.name = 'img2zpl'
7
- spec.version = Img2Zpl::VERSION
8
- spec.authors = ['Michael King']
9
- spec.email = 'mtking1123@gmail.com'
10
- spec.summary = 'Convert images to ZPL'
11
- spec.description = 'Ruby library to convert images to usable & printable ZPL code'
5
+ spec.name = "img2zpl"
6
+ spec.version = Img2Zpl::VERSION
7
+ spec.authors = ["Michael King"]
8
+ spec.email = "m.king@fastmail.com"
9
+ spec.summary = "Convert images to ZPL"
10
+ spec.description = "Ruby library to convert images to usable & printable ZPL code"
12
11
 
13
- spec.homepage = "https://github.com/mtking2/img2zpl"
14
- spec.license = 'MIT'
12
+ spec.homepage = "https://github.com/mtking2/img2zpl"
13
+ spec.license = "MIT"
15
14
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.test_files = `git ls-files -- spec/*`.split("\n")
18
- spec.require_paths = ['lib']
15
+ spec.files = `git ls-files`.split($/)
16
+ spec.require_paths = ["lib"]
19
17
 
20
- spec.add_dependency 'mini_magick', '~> 4.9'
21
- spec.add_development_dependency 'rake', '~> 13'
22
- spec.add_development_dependency 'rspec', '~> 3.9'
18
+ spec.add_dependency "mini_magick", ">= 4.9"
19
+ spec.add_development_dependency "rake", "~> 13"
20
+ spec.add_development_dependency "rspec", "~> 3.9"
23
21
  end
data/lib/img2zpl/image.rb CHANGED
@@ -1,64 +1,70 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Img2Zpl
2
- class Image < MiniMagick::Image
3
4
 
4
- def to_zpl(black_threshold: 0.5, invert: false, compress: true)
5
- bytes_per_row = (width % 8).positive? ? (width / 8) + 1 : (width / 8)
6
- byte_count = bytes_per_row * height
7
- data, line, previous_line, byte = '', '', '', ''
5
+ class Image < MiniMagick::Image
6
+
7
+ def to_zpl(black_threshold: 0.5, invert: false, compress: true)
8
+ bytes_per_row = (width % 8).positive? ? (width / 8) + 1 : (width / 8)
9
+ byte_count = bytes_per_row * height
10
+ data, line, previous_line, byte = Array.new(4, +"")
11
+
12
+ get_pixels.each do |row|
13
+ row.each_with_index do |column, i|
14
+ r, g, b = column.map(&:to_i)
15
+ b_dot, w_dot = invert ? %w[1 0] : %w[0 1]
16
+ byte << (((r + g + b) > (black_threshold * 765)) ? b_dot : w_dot)
17
+
18
+ if ((i + 1) % 8).zero? || i == (width - 1)
19
+ line_str = byte.ljust(8, "0").to_i(2).to_s(16).upcase.rjust(2, "0")
20
+ line << line_str
21
+ byte = +""
22
+ end
23
+ end
8
24
 
9
- get_pixels.each do |row|
10
- row.each_with_index do |column, i|
11
- r, g, b = column.map(&:to_i)
12
- b_dot, w_dot = invert ? %w(1 0) : %w(0 1)
13
- byte << ((r + g + b) > (black_threshold * 765) ? b_dot : w_dot)
14
- if (i % 8).zero?
15
- line << byte.to_i(2).to_s(16).upcase.rjust(2, '0')
16
- byte = ''
17
- end
18
- end
25
+ data << if compress
26
+ ((line == previous_line) ? ":" : line.gsub(/0+$/, ",").gsub(/F+$/, "!"))
27
+ else
28
+ line
29
+ end
19
30
 
20
- data << if compress
21
- (line == previous_line ? ':' : line.gsub(/0+$/, ',').gsub(/F+$/, '!'))
22
- else
23
- line
24
- end
31
+ previous_line = line
32
+ line = +""
33
+ end
25
34
 
26
- previous_line = line
27
- line = ''
28
- end
35
+ _compress(data) if compress
36
+ "^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
37
+ end
29
38
 
30
- _compress(data) if compress
31
- "^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
32
- end
39
+ private
33
40
 
34
- private
41
+ def _compression_map
42
+ map = {}
43
+ start = "G".ord
44
+ 19.times { |i| map[i + 1] = (start + i).chr }
45
+ start = "g".ord
46
+ (20..400).step(20).each_with_index { |i, j| map[i] = (start + j).chr }
47
+ map
48
+ end
35
49
 
36
- def _compression_map
37
- map = {}
38
- start = 'G'.ord
39
- 19.times { |i| map[i + 1] = (start+i).chr }
40
- start = 'g'.ord
41
- (20..400).step(20).each_with_index { |i, j| map[i] = (start+j).chr }
42
- map
43
- end
50
+ def _reduce(n)
51
+ str = +""
52
+ counts = _compression_map.keys.sort.reverse
53
+ counts.each do |c|
54
+ if c <= n
55
+ str << _compression_map[c]
56
+ n -= c
57
+ end
58
+ end
59
+ str
60
+ end
44
61
 
45
- def _reduce(n)
46
- str = ''
47
- counts = _compression_map.keys.sort.reverse
48
- counts.each do |c|
49
- if c <= n
50
- str << (_compression_map[c])
51
- n -= c
52
- end
53
- end
54
- str
55
- end
62
+ def _compress(data)
63
+ data.gsub!(/([\da-zA-Z])(\1+)/) do |m|
64
+ (m.length == 2) ? m : "#{_reduce(m.length)}#{$1}"
65
+ end
66
+ end
56
67
 
57
- def _compress(data)
58
- data.gsub!(/([\da-zA-Z])(\1+)/) do |m|
59
- "#{_reduce(m.length)}#{$1}"
60
- end
61
- end
68
+ end
62
69
 
63
- end
64
70
  end
@@ -1,3 +1,5 @@
1
1
  module Img2Zpl
2
- VERSION = '1.0.0'
2
+
3
+ VERSION = "1.0.2".freeze
4
+
3
5
  end
data/lib/img2zpl.rb CHANGED
@@ -1,2 +1,2 @@
1
- require 'mini_magick'
2
- require_relative 'img2zpl/image'
1
+ require "mini_magick"
2
+ require_relative "img2zpl/image"
@@ -1,72 +1,82 @@
1
- require 'spec_helper'
1
+ require "spec_helper"
2
2
 
3
- describe Img2Zpl::Image do
3
+ describe Img2Zpl::Image do # rubocop:disable RSpec/SpecFilePathFormat
4
+ subject(:image) { described_class.open("spec/fixtures/default.jpg") }
4
5
 
5
- subject { described_class.open('spec/fixtures/default.jpg') }
6
+ it "inherits from the MiniMagick::Image class" do
7
+ expect(described_class.respond_to?(:open)).to be true
8
+ expect(described_class.respond_to?(:read)).to be true
9
+ end
6
10
 
7
- it 'should inherit from the MiniMagick::Image class' do
8
- expect(described_class.respond_to?(:open)).to be true
9
- expect(described_class.respond_to?(:read)).to be true
10
- expect(subject.respond_to?(:to_zpl)).to be true
11
- end
11
+ it "implements the .to_zpl method" do
12
+ expect(image.respond_to?(:to_zpl)).to be true
13
+ end
12
14
 
13
- it 'should have the compression map' do
14
- map = subject.send(:_compression_map)
15
- expect(map[1]).to eq 'G'
16
- expect(map[2]).to eq 'H'
17
- expect(map[3]).to eq 'I'
18
- expect(map[4]).to eq 'J'
19
- expect(map[5]).to eq 'K'
20
- expect(map[6]).to eq 'L'
21
- expect(map[7]).to eq 'M'
22
- expect(map[8]).to eq 'N'
23
- expect(map[9]).to eq 'O'
24
- expect(map[10]).to eq 'P'
25
- expect(map[11]).to eq 'Q'
26
- expect(map[12]).to eq 'R'
27
- expect(map[13]).to eq 'S'
28
- expect(map[14]).to eq 'T'
29
- expect(map[15]).to eq 'U'
30
- expect(map[16]).to eq 'V'
31
- expect(map[17]).to eq 'W'
32
- expect(map[18]).to eq 'X'
33
- expect(map[19]).to eq 'Y'
34
- expect(map[20]).to eq 'g'
35
- expect(map[40]).to eq 'h'
36
- expect(map[60]).to eq 'i'
37
- expect(map[80]).to eq 'j'
38
- expect(map[100]).to eq 'k'
39
- expect(map[120]).to eq 'l'
40
- expect(map[140]).to eq 'm'
41
- expect(map[160]).to eq 'n'
42
- expect(map[180]).to eq 'o'
43
- expect(map[200]).to eq 'p'
44
- expect(map[220]).to eq 'q'
45
- expect(map[240]).to eq 'r'
46
- expect(map[260]).to eq 's'
47
- expect(map[280]).to eq 't'
48
- expect(map[300]).to eq 'u'
49
- expect(map[320]).to eq 'v'
50
- expect(map[340]).to eq 'w'
51
- expect(map[360]).to eq 'x'
52
- expect(map[380]).to eq 'y'
53
- expect(map[400]).to eq 'z'
54
- end
15
+ it "has the compression map" do # rubocop:disable RSpec/ExampleLength
16
+ map = image.send(:_compression_map)
17
+ expect(map).to eq({
18
+ 1 => "G",
19
+ 2 => "H",
20
+ 3 => "I",
21
+ 4 => "J",
22
+ 5 => "K",
23
+ 6 => "L",
24
+ 7 => "M",
25
+ 8 => "N",
26
+ 9 => "O",
27
+ 10 => "P",
28
+ 11 => "Q",
29
+ 12 => "R",
30
+ 13 => "S",
31
+ 14 => "T",
32
+ 15 => "U",
33
+ 16 => "V",
34
+ 17 => "W",
35
+ 18 => "X",
36
+ 19 => "Y",
37
+ 20 => "g",
38
+ 40 => "h",
39
+ 60 => "i",
40
+ 80 => "j",
41
+ 100 => "k",
42
+ 120 => "l",
43
+ 140 => "m",
44
+ 160 => "n",
45
+ 180 => "o",
46
+ 200 => "p",
47
+ 220 => "q",
48
+ 240 => "r",
49
+ 260 => "s",
50
+ 280 => "t",
51
+ 300 => "u",
52
+ 320 => "v",
53
+ 340 => "w",
54
+ 360 => "x",
55
+ 380 => "y",
56
+ 400 => "z"
57
+ })
58
+ end
55
59
 
56
- it 'should properly compress ASCII data' do
57
- d1 = '00000000000000000000000000000000000000000000000000000000008'
58
- d2 = '5555555555555ADDDDDDDDDDDDDDDDDDDDDDD'
59
- d3 = '00000000FFFFFFFFFFFFFFFFFFFFFFC0000000000000000000007FFFFFFFFF'
60
- subject.send(:_compress, d1)
61
- subject.send(:_compress, d2)
62
- subject.send(:_compress, d3)
63
- expect(d1).to eq 'hX08'
64
- expect(d2).to eq 'S5AgID'
65
- expect(d3).to eq 'N0gHFCgG07OF'
66
- end
60
+ context "with example data" do
61
+ let(:example_data_sets) {
62
+ [
63
+ { data: "00000000000000000000000000000000000000000000000000000000008", result: "hX08" },
64
+ { data: "5555555555555ADDDDDDDDDDDDDDDDDDDDDDD", result: "S5AgID" },
65
+ { data: "00000000FFFFFFFFFFFFFFFFFFFFFFC0000000000000000000007FFFFFFFFF", result: "N0gHFCgG07OF" }
66
+ ]
67
+ }
67
68
 
68
- it 'should return a string when calling .to_zpl' do
69
- expect(subject.to_zpl).to be_kind_of String
70
- end
69
+ it "properly compresses ASCII data" do
70
+ example_data_sets.each do |data_set|
71
+ data = data_set[:data]
72
+ result = data_set[:result]
73
+ image.send(:_compress, data)
74
+ expect(data).to eq(result)
75
+ end
76
+ end
77
+ end
71
78
 
79
+ it "returns a string when calling .to_zpl" do
80
+ expect(image.to_zpl).to be_a String
81
+ end
72
82
  end
data/spec/spec_helper.rb CHANGED
@@ -13,94 +13,89 @@
13
13
  # it.
14
14
  #
15
15
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
- require 'img2zpl'
17
- require 'byebug'
18
- require 'pry'
19
- require 'pry-nav'
20
-
16
+ require "img2zpl"
17
+ require "debug"
21
18
 
22
19
  RSpec.configure do |config|
23
- # rspec-expectations config goes here. You can use an alternate
24
- # assertion/expectation library such as wrong or the stdlib/minitest
25
- # assertions if you prefer.
26
- config.expect_with :rspec do |expectations|
27
- # This option will default to `true` in RSpec 4. It makes the `description`
28
- # and `failure_message` of custom matchers include text for helper methods
29
- # defined using `chain`, e.g.:
30
- # be_bigger_than(2).and_smaller_than(4).description
31
- # # => "be bigger than 2 and smaller than 4"
32
- # ...rather than:
33
- # # => "be bigger than 2"
34
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
35
- end
36
-
37
- # rspec-mocks config goes here. You can use an alternate test double
38
- # library (such as bogus or mocha) by changing the `mock_with` option here.
39
- config.mock_with :rspec do |mocks|
40
- # Prevents you from mocking or stubbing a method that does not exist on
41
- # a real object. This is generally recommended, and will default to
42
- # `true` in RSpec 4.
43
- mocks.verify_partial_doubles = true
44
- end
45
-
46
- # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
47
- # have no way to turn it off -- the option exists only for backwards
48
- # compatibility in RSpec 3). It causes shared context metadata to be
49
- # inherited by the metadata hash of host groups and examples, rather than
50
- # triggering implicit auto-inclusion in groups with matching metadata.
51
- config.shared_context_metadata_behavior = :apply_to_host_groups
52
-
53
- # The settings below are suggested to provide a good initial experience
54
- # with RSpec, but feel free to customize to your heart's content.
55
- =begin
56
- # This allows you to limit a spec run to individual examples or groups
57
- # you care about by tagging them with `:focus` metadata. When nothing
58
- # is tagged with `:focus`, all examples get run. RSpec also provides
59
- # aliases for `it`, `describe`, and `context` that include `:focus`
60
- # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
61
- config.filter_run_when_matching :focus
62
-
63
- # Allows RSpec to persist some state between runs in order to support
64
- # the `--only-failures` and `--next-failure` CLI options. We recommend
65
- # you configure your source control system to ignore this file.
66
- config.example_status_persistence_file_path = "spec/examples.txt"
67
-
68
- # Limits the available syntax to the non-monkey patched syntax that is
69
- # recommended. For more details, see:
70
- # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
71
- # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
72
- # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
73
- config.disable_monkey_patching!
74
-
75
- # This setting enables warnings. It's recommended, but in some cases may
76
- # be too noisy due to issues in dependencies.
77
- config.warnings = true
78
-
79
- # Many RSpec users commonly either run the entire suite or an individual
80
- # file, and it's useful to allow more verbose output when running an
81
- # individual spec file.
82
- if config.files_to_run.one?
83
- # Use the documentation formatter for detailed output,
84
- # unless a formatter has already been configured
85
- # (e.g. via a command-line flag).
86
- config.default_formatter = "doc"
87
- end
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
88
33
 
89
- # Print the 10 slowest examples and example groups at the
90
- # end of the spec run, to help surface which specs are running
91
- # particularly slow.
92
- config.profile_examples = 10
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
93
42
 
94
- # Run specs in random order to surface order dependencies. If you find an
95
- # order dependency and want to debug it, you can fix the order by providing
96
- # the seed, which is printed after each run.
97
- # --seed 1234
98
- config.order = :random
43
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
44
+ # have no way to turn it off -- the option exists only for backwards
45
+ # compatibility in RSpec 3). It causes shared context metadata to be
46
+ # inherited by the metadata hash of host groups and examples, rather than
47
+ # triggering implicit auto-inclusion in groups with matching metadata.
48
+ config.shared_context_metadata_behavior = :apply_to_host_groups
99
49
 
100
- # Seed global randomization in this process using the `--seed` CLI option.
101
- # Setting this allows you to use `--seed` to deterministically reproduce
102
- # test failures related to randomization by passing the same `--seed` value
103
- # as the one that triggered the failure.
104
- Kernel.srand config.seed
105
- =end
50
+ # The settings below are suggested to provide a good initial experience
51
+ # with RSpec, but feel free to customize to your heart's content.
52
+ # # This allows you to limit a spec run to individual examples or groups
53
+ # # you care about by tagging them with `:focus` metadata. When nothing
54
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ # config.filter_run_when_matching :focus
58
+ #
59
+ # # Allows RSpec to persist some state between runs in order to support
60
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # # you configure your source control system to ignore this file.
62
+ # config.example_status_persistence_file_path = "spec/examples.txt"
63
+ #
64
+ # # Limits the available syntax to the non-monkey patched syntax that is
65
+ # # recommended. For more details, see:
66
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
67
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
68
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
69
+ # config.disable_monkey_patching!
70
+ #
71
+ # # This setting enables warnings. It's recommended, but in some cases may
72
+ # # be too noisy due to issues in dependencies.
73
+ # config.warnings = true
74
+ #
75
+ # # Many RSpec users commonly either run the entire suite or an individual
76
+ # # file, and it's useful to allow more verbose output when running an
77
+ # # individual spec file.
78
+ # if config.files_to_run.one?
79
+ # # Use the documentation formatter for detailed output,
80
+ # # unless a formatter has already been configured
81
+ # # (e.g. via a command-line flag).
82
+ # config.default_formatter = "doc"
83
+ # end
84
+ #
85
+ # # Print the 10 slowest examples and example groups at the
86
+ # # end of the spec run, to help surface which specs are running
87
+ # # particularly slow.
88
+ # config.profile_examples = 10
89
+ #
90
+ # # Run specs in random order to surface order dependencies. If you find an
91
+ # # order dependency and want to debug it, you can fix the order by providing
92
+ # # the seed, which is printed after each run.
93
+ # # --seed 1234
94
+ # config.order = :random
95
+ #
96
+ # # Seed global randomization in this process using the `--seed` CLI option.
97
+ # # Setting this allows you to use `--seed` to deterministically reproduce
98
+ # # test failures related to randomization by passing the same `--seed` value
99
+ # # as the one that triggered the failure.
100
+ # Kernel.srand config.seed
106
101
  end
metadata CHANGED
@@ -1,27 +1,26 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: img2zpl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael King
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2019-10-31 00:00:00.000000000 Z
10
+ date: 2025-05-22 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: mini_magick
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - "~>"
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '4.9'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - "~>"
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '4.9'
27
26
  - !ruby/object:Gem::Dependency
@@ -53,19 +52,27 @@ dependencies:
53
52
  - !ruby/object:Gem::Version
54
53
  version: '3.9'
55
54
  description: Ruby library to convert images to usable & printable ZPL code
56
- email: mtking1123@gmail.com
55
+ email: m.king@fastmail.com
57
56
  executables: []
58
57
  extensions: []
59
58
  extra_rdoc_files: []
60
59
  files:
60
+ - ".github/workflows/lint-and-test.yml"
61
61
  - ".gitignore"
62
62
  - ".rspec"
63
+ - ".rubocop.yml"
64
+ - ".ruby-version"
63
65
  - CHANGELOG.md
64
66
  - CONTRIBUTING.md
65
67
  - Gemfile
66
68
  - LICENSE
67
69
  - README.md
68
70
  - Rakefile
71
+ - bin/bundle
72
+ - bin/console
73
+ - bin/rspec
74
+ - bin/rubocop
75
+ - bin/setup
69
76
  - img2zpl.gemspec
70
77
  - lib/img2zpl.rb
71
78
  - lib/img2zpl/image.rb
@@ -77,7 +84,6 @@ homepage: https://github.com/mtking2/img2zpl
77
84
  licenses:
78
85
  - MIT
79
86
  metadata: {}
80
- post_install_message:
81
87
  rdoc_options: []
82
88
  require_paths:
83
89
  - lib
@@ -92,11 +98,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
92
98
  - !ruby/object:Gem::Version
93
99
  version: '0'
94
100
  requirements: []
95
- rubygems_version: 3.0.6
96
- signing_key:
101
+ rubygems_version: 3.6.2
97
102
  specification_version: 4
98
103
  summary: Convert images to ZPL
99
- test_files:
100
- - spec/fixtures/default.jpg
101
- - spec/img2zpl/image_spec.rb
102
- - spec/spec_helper.rb
104
+ test_files: []