img2zpl 1.0.1 → 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 +4 -4
- data/.github/workflows/lint-and-test.yml +42 -0
- data/.gitignore +2 -0
- data/.rubocop.yml +41 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +1 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile +6 -4
- data/Rakefile +6 -6
- data/bin/bundle +109 -0
- data/bin/console +14 -0
- data/bin/rspec +27 -0
- data/bin/rubocop +27 -0
- data/bin/setup +8 -0
- data/img2zpl.gemspec +15 -17
- data/lib/img2zpl/image.rb +57 -53
- data/lib/img2zpl/version.rb +3 -1
- data/lib/img2zpl.rb +2 -2
- data/spec/img2zpl/image_spec.rb +74 -64
- data/spec/spec_helper.rb +80 -85
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85f87b66f8684ac6b08e864c77dfadeb5fe4af4d5e123c51936f16038b302759
|
4
|
+
data.tar.gz: 71c21dd57dcb10359496f5cb5fb77b82ca95009d3aaf849076c5cceaf57de0f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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
data/CONTRIBUTING.md
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
source
|
1
|
+
source "https://rubygems.org"
|
2
2
|
|
3
3
|
group :development, :test do
|
4
|
-
|
5
|
-
|
6
|
-
|
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/Rakefile
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "rubygems"
|
2
|
+
require "bundler"
|
3
|
+
require "bundler/gem_tasks"
|
4
4
|
|
5
5
|
Bundler.setup :default, :development
|
6
6
|
|
7
|
-
require
|
8
|
-
require
|
7
|
+
require "rspec/core"
|
8
|
+
require "rspec/core/rake_task"
|
9
9
|
|
10
10
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
-
|
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
data/img2zpl.gemspec
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
-
|
2
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
12
|
+
spec.homepage = "https://github.com/mtking2/img2zpl"
|
13
|
+
spec.license = "MIT"
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
spec.require_paths = ['lib']
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.require_paths = ["lib"]
|
19
17
|
|
20
|
-
|
21
|
-
|
22
|
-
|
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,66 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Img2Zpl
|
2
|
-
class Image < MiniMagick::Image
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
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)
|
8
17
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
14
24
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
end
|
25
|
+
data << if compress
|
26
|
+
((line == previous_line) ? ":" : line.gsub(/0+$/, ",").gsub(/F+$/, "!"))
|
27
|
+
else
|
28
|
+
line
|
29
|
+
end
|
21
30
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
line
|
26
|
-
end
|
31
|
+
previous_line = line
|
32
|
+
line = +""
|
33
|
+
end
|
27
34
|
|
28
|
-
|
29
|
-
|
30
|
-
|
35
|
+
_compress(data) if compress
|
36
|
+
"^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
|
37
|
+
end
|
31
38
|
|
32
|
-
|
33
|
-
"^GFA,#{byte_count},#{byte_count},#{bytes_per_row},#{data}^FS"
|
34
|
-
end
|
39
|
+
private
|
35
40
|
|
36
|
-
|
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
|
37
49
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
46
61
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
str << (_compression_map[c])
|
53
|
-
n -= c
|
54
|
-
end
|
55
|
-
end
|
56
|
-
str
|
57
|
-
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
|
58
67
|
|
59
|
-
|
60
|
-
data.gsub!(/([\da-zA-Z])(\1+)/) do |m|
|
61
|
-
m.length == 2 ? m : "#{_reduce(m.length)}#{$1}"
|
62
|
-
end
|
63
|
-
end
|
68
|
+
end
|
64
69
|
|
65
|
-
end
|
66
70
|
end
|
data/lib/img2zpl/version.rb
CHANGED
data/lib/img2zpl.rb
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
require_relative
|
1
|
+
require "mini_magick"
|
2
|
+
require_relative "img2zpl/image"
|
data/spec/img2zpl/image_spec.rb
CHANGED
@@ -1,72 +1,82 @@
|
|
1
|
-
require
|
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
|
-
|
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
|
-
|
8
|
-
|
9
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
69
|
-
|
70
|
-
|
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
|
17
|
-
require
|
18
|
-
require 'pry'
|
19
|
-
require 'pry-nav'
|
20
|
-
|
16
|
+
require "img2zpl"
|
17
|
+
require "debug"
|
21
18
|
|
22
19
|
RSpec.configure do |config|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
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
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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.
|
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:
|
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:
|
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.
|
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: []
|