From 377acdf0930fe8e148ef97ce06e551a8f5746c1c Mon Sep 17 00:00:00 2001 From: LagTag Date: Mon, 14 Oct 2019 20:37:28 -0400 Subject: [PATCH 01/12] no bold --- lib/zebra/zpl/text.rb | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index 86857a5..e61f002 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -7,7 +7,7 @@ class Text class InvalidMaxLinesError < StandardError; end - attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent, :bold + attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent def font_size=(f) FontSize.validate_font_size f @@ -86,10 +86,6 @@ def v_multiplier=(multiplier) def to_zpl check_attributes "^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" - if bold.present? - zpl += "^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x+2},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" - zpl += "^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y+2}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" - end end private From 625500aee498688e877ffae0596a52b57332c033 Mon Sep 17 00:00:00 2001 From: LagTag Date: Mon, 14 Oct 2019 20:47:22 -0400 Subject: [PATCH 02/12] consistency --- lib/zebra/zpl/text.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index e61f002..475e2e3 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -14,10 +14,6 @@ def font_size=(f) @font_size = f end - def bold=(value) - @bold = value - end - def width=(width) unless (margin.nil? || margin < 1) @width = (width - (margin*2)) @@ -85,6 +81,10 @@ def v_multiplier=(multiplier) def to_zpl check_attributes + # ["A#{x}", y, rotation, font_size, h_multiplier, v_multiplier, print_mode, "\"#{data}\""].join(",") + # "^FO25,25^FB600,100,0,C,0^FDFoo^FS" + + # "^CF#{font_type},#{font_size}^FO#{x},#{y}^FB609,4,0,#{justification},0^FD#{data}^FS" "^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" end From bf9e2188b7cad15130dff937d3c14d20a8713ca8 Mon Sep 17 00:00:00 2001 From: LagTag Date: Mon, 14 Oct 2019 20:48:53 -0400 Subject: [PATCH 03/12] c --- lib/zebra/zpl/text.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index 475e2e3..3d6e651 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -81,8 +81,8 @@ def v_multiplier=(multiplier) def to_zpl check_attributes - # ["A#{x}", y, rotation, font_size, h_multiplier, v_multiplier, print_mode, "\"#{data}\""].join(",") - # "^FO25,25^FB600,100,0,C,0^FDFoo^FS" + # ["A#{x}", y, rotation, font_size, h_multiplier, v_multiplier, print_mode, "\"#{data}\""].join(",") + # "^FO25,25^FB600,100,0,C,0^FDFoo^FS" # "^CF#{font_type},#{font_size}^FO#{x},#{y}^FB609,4,0,#{justification},0^FD#{data}^FS" "^FW#{rotation}^CF#{font_type},#{font_size}^CI28^FO#{x},#{y}^FB#{width},#{max_lines},#{line_spacing},#{justification},#{hanging_indent}^FD#{data}^FS" From 24bdacdd97612e0497474b33b8f43ca099393415 Mon Sep 17 00:00:00 2001 From: LagTag Date: Mon, 14 Oct 2019 22:25:29 -0400 Subject: [PATCH 04/12] Consolidate graphic elements into one class --- lib/zebra/zpl.rb | 1 + lib/zebra/zpl/graphic.rb | 83 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 lib/zebra/zpl/graphic.rb diff --git a/lib/zebra/zpl.rb b/lib/zebra/zpl.rb index bb768a7..2607e4d 100644 --- a/lib/zebra/zpl.rb +++ b/lib/zebra/zpl.rb @@ -20,3 +20,4 @@ require 'zebra/zpl/pdf417' require 'zebra/zpl/justification' require 'zebra/zpl/raw' +require 'zebra/zpl/graphic' diff --git a/lib/zebra/zpl/graphic.rb b/lib/zebra/zpl/graphic.rb new file mode 100644 index 0000000..4dd421e --- /dev/null +++ b/lib/zebra/zpl/graphic.rb @@ -0,0 +1,83 @@ +require "zebra/zpl/printable" + +module Zebra + module Zpl + class Graphic + include Printable + + class InvalidLineThickness < StandardError; end + class InvalidColorError < StandardError; end + class InvalidOrientationError < StandardError; end + class InvalidGraphicType < StandardError; end + + alias_attribute :diameter, :graphic_width + + attr_reader :line_thickness, :graphic_width, :graphic_height, :color, :orientation, :rounding_degree, :graphic_type + + ELIPSE = "E" + BOX = "B" + DIAGONAL = "D" + CIRCLE = "C" + SYMBOL = "S" + + def graphic_type=(type) + raise InvalidGraphicType unless %w(E B D C S).include? type + @graphic_type = type + end + + def self.valid_graphic_type?(type) + + end + + def line_thickness=(thickness) + raise InvalidLineThickness unless thickness.nil? || thickness.to_i.to_s == thickness.to_s + @line_thickness = thickness + end + + def graphic_width=(width) + @graphic_width = width + end + + def graphic_height=(height) + @graphic_height = height + end + + def color=(value) + raise InvalidColorError unless value&.upcase.in?(["B","W"]) + @color = value + end + + def orientation=(value) + raise InvalidOrientationError unless value&.upcase.in?(["R","L"]) + @orientation = value + end + + def to_zpl + check_attributes + zpl = case graphic_type + when "B" + "D#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}" + when "E" + "E#{graphic_width},#{graphic_height},#{line_thickness},#{color}" + when "C" + "C#{diameter},#{line_thickness},#{color}" + when "D" + "D#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}" + when "S" + "S#{orientation},#{graphic_height},#{graphic_width}" + end + "^FO#{x},#{y}^G#{zpl}^FS" + end + + private + + def has_data? + false + end + + def check_attributes + super + end + end + end +end From a439012b3b537f16d86721d74b4baca98ee3654c Mon Sep 17 00:00:00 2001 From: LagTag Date: Tue, 15 Oct 2019 09:14:54 -0400 Subject: [PATCH 05/12] B for box --- lib/zebra/zpl/graphic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/zebra/zpl/graphic.rb b/lib/zebra/zpl/graphic.rb index 4dd421e..83b14eb 100644 --- a/lib/zebra/zpl/graphic.rb +++ b/lib/zebra/zpl/graphic.rb @@ -56,7 +56,7 @@ def to_zpl check_attributes zpl = case graphic_type when "B" - "D#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}" + "B#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}" when "E" "E#{graphic_width},#{graphic_height},#{line_thickness},#{color}" when "C" From 687fc44f54e3dd6bd41093b9461b02c6e5e02a3b Mon Sep 17 00:00:00 2001 From: LagTag Date: Tue, 15 Oct 2019 16:36:50 -0400 Subject: [PATCH 06/12] remove rails specific methods --- lib/zebra/zpl/graphic.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zebra/zpl/graphic.rb b/lib/zebra/zpl/graphic.rb index 83b14eb..e050bf2 100644 --- a/lib/zebra/zpl/graphic.rb +++ b/lib/zebra/zpl/graphic.rb @@ -43,12 +43,12 @@ def graphic_height=(height) end def color=(value) - raise InvalidColorError unless value&.upcase.in?(["B","W"]) + raise InvalidColorError unless %w[R L].include?(value&.upcase) @color = value end def orientation=(value) - raise InvalidOrientationError unless value&.upcase.in?(["R","L"]) + raise InvalidOrientationError unless %w[R L].include?(value&.upcase) @orientation = value end From d2efc589793903b99d19c277c60f2864d174a537 Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 13:21:04 -0400 Subject: [PATCH 07/12] Rspec tests --- lib/zebra/zpl/box.rb | 1 + lib/zebra/zpl/circle.rb | 44 ----------- lib/zebra/zpl/diagonal.rb | 55 ------------- lib/zebra/zpl/graphic.rb | 12 +-- spec/zebra/zpl/graphics_spec.rb | 133 ++++++++++++++++++++++++++++++++ 5 files changed, 138 insertions(+), 107 deletions(-) delete mode 100644 lib/zebra/zpl/circle.rb delete mode 100644 lib/zebra/zpl/diagonal.rb create mode 100644 spec/zebra/zpl/graphics_spec.rb diff --git a/lib/zebra/zpl/box.rb b/lib/zebra/zpl/box.rb index d3bdb06..a274804 100644 --- a/lib/zebra/zpl/box.rb +++ b/lib/zebra/zpl/box.rb @@ -41,6 +41,7 @@ def color=(value) def to_zpl check_attributes + puts "The Box class is deprecated. Please switch to the Graphic class (graphic_type = box)." "^FO#{x},#{y}^GB#{box_width},#{box_height},#{line_thickness},#{color},#{rounding_degree}^FS" end diff --git a/lib/zebra/zpl/circle.rb b/lib/zebra/zpl/circle.rb deleted file mode 100644 index 765b6fe..0000000 --- a/lib/zebra/zpl/circle.rb +++ /dev/null @@ -1,44 +0,0 @@ -require "zebra/zpl/printable" - -module Zebra - module Zpl - class Circle - include Printable - - class InvalidLineThickness < StandardError; end - class InvalidColorError < StandardError; end - - attr_reader :line_thickness, :diameter, :color - - def line_thickness=(thickness) - raise InvalidLineThickness unless thickness.nil? || thickness.to_i.to_s == thickness.to_s - @line_thickness = thickness - end - - def diameter=(value) - @diameter = value - end - - def color=(value) - raise InvalidColorError unless %w[B W].include?(value&.upcase) - @color = value - end - - def to_zpl - check_attributes - "^FO#{x},#{y}^GC#{diameter},#{line_thickness},#{color}^FS" - end - - private - - def has_data? - false - end - - def check_attributes - super - raise MissingAttributeError.new("the circle diameter is not given") unless diameter - end - end - end -end diff --git a/lib/zebra/zpl/diagonal.rb b/lib/zebra/zpl/diagonal.rb deleted file mode 100644 index 383e78b..0000000 --- a/lib/zebra/zpl/diagonal.rb +++ /dev/null @@ -1,55 +0,0 @@ -require "zebra/zpl/printable" - -module Zebra - module Zpl - class Diagonal - include Printable - - class InvalidLineThickness < StandardError; end - class InvalidColorError < StandardError; end - class InvalidOrientationError < StandardError; end - - attr_reader :line_thickness, :box_width, :box_height, :color, :orientation - - def line_thickness=(thickness) - raise InvalidLineThickness unless thickness.nil? || thickness.to_i.to_s == thickness.to_s - @line_thickness = thickness - end - - def box_width=(width) - @box_width = width - end - - def box_height=(height) - @box_height = height - end - - def color=(value) - raise InvalidColorError unless %w[B W].include?(value&.upcase) - @color = value - end - - def orientation=(value) - raise InvalidOrientationError unless %w[R L].include?(value&.upcase) - @orientation = value - end - - def to_zpl - check_attributes - "^FO#{x},#{y}^GD#{box_width},#{box_height},#{line_thickness},#{color},#{orientation}^FS" - end - - private - - def has_data? - false - end - - def check_attributes - super - raise MissingAttributeError.new("the box_width is not given") unless box_width - raise MissingAttributeError.new("the box_height is not given") unless box_height - end - end - end -end diff --git a/lib/zebra/zpl/graphic.rb b/lib/zebra/zpl/graphic.rb index e050bf2..eba9322 100644 --- a/lib/zebra/zpl/graphic.rb +++ b/lib/zebra/zpl/graphic.rb @@ -10,9 +10,8 @@ class InvalidColorError < StandardError; end class InvalidOrientationError < StandardError; end class InvalidGraphicType < StandardError; end - alias_attribute :diameter, :graphic_width - attr_reader :line_thickness, :graphic_width, :graphic_height, :color, :orientation, :rounding_degree, :graphic_type + attr_writer :rounding_degree ELIPSE = "E" BOX = "B" @@ -25,10 +24,6 @@ def graphic_type=(type) @graphic_type = type end - def self.valid_graphic_type?(type) - - end - def line_thickness=(thickness) raise InvalidLineThickness unless thickness.nil? || thickness.to_i.to_s == thickness.to_s @line_thickness = thickness @@ -43,7 +38,7 @@ def graphic_height=(height) end def color=(value) - raise InvalidColorError unless %w[R L].include?(value&.upcase) + raise InvalidColorError unless %w[B W].include?(value&.upcase) @color = value end @@ -60,7 +55,7 @@ def to_zpl when "E" "E#{graphic_width},#{graphic_height},#{line_thickness},#{color}" when "C" - "C#{diameter},#{line_thickness},#{color}" + "C#{graphic_width},#{line_thickness},#{color}" when "D" "D#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}" when "S" @@ -77,6 +72,7 @@ def has_data? def check_attributes super + raise InvalidGraphicType if @graphic_type.nil? end end end diff --git a/spec/zebra/zpl/graphics_spec.rb b/spec/zebra/zpl/graphics_spec.rb new file mode 100644 index 0000000..84ea699 --- /dev/null +++ b/spec/zebra/zpl/graphics_spec.rb @@ -0,0 +1,133 @@ +require 'spec_helper' + +describe Zebra::Zpl::Graphic do + it "can be initialized with graphic type" do + graphic = described_class.new graphic_type: Zebra::Zpl::Graphic::ELIPSE + expect(graphic.graphic_type).to eq "E" + end + + it "can be initialized with a graphic width" do + graphic = described_class.new graphic_width: 30 + expect(graphic.graphic_width).to eq 30 + end + + it "can be initialized with a graphic height" do + graphic = described_class.new graphic_height: 30 + expect(graphic.graphic_height).to eq 30 + end + + it "can be initialized with a line_thickness" do + graphic = described_class.new line_thickness: 3 + expect(graphic.line_thickness).to eq 3 + end + + it "can be initialized with a color" do + graphic = described_class.new color: "W" + expect(graphic.color).to eq "W" + end + + it "can be initialized with an orientation" do + graphic = described_class.new orientation: "R" + expect(graphic.orientation).to eq "R" + end + + it "can be initialized with a rounding degree" do + graphic = described_class.new rounding_degree: 2 + expect(graphic.rounding_degree).to eq 2 + end + + + + describe "#orientation" do + it "raises an error if the orientation not in [N L]" do + expect { described_class.new orientation: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidOrientationError) + end + end + + describe "#color" do + it "raises an error if the color not in [B W]" do + expect { described_class.new color: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidColorError) + end + end + + describe "#line_thickness" do + it "raises an error if line thickness is not a number" do + expect { described_class.new line_thickness: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidLineThickness) + end + end + + describe "#graphic_type" do + it "raises an error if the graphic type not in [E B D C S]" do + expect { described_class.new graphic_type: 'A' }.to raise_error(Zebra::Zpl::Graphic::InvalidGraphicType) + end + end + + describe "#to_zpl" do + let(:valid_attributes) { { + position: [50, 50], + graphic_type: Zebra::Zpl::Graphic::ELIPSE + }} + let(:graphic_elipse) { described_class.new valid_attributes } + let(:graphic_diaganol) { described_class.new } + let(:graphic_box) { described_class.new } + let(:graphic_symbol) { described_class.new } + let(:graphic_circle) { described_class.new } + + let(:tokens_elipse) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_diaganol) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_box) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_symbol) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_circle) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + + it "raises an error if the X position is not given" do + graphic = described_class.new position: [nil, 50], graphic_type: described_class::ELIPSE + expect { + graphic.to_zpl + }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given") + end + + it "raises an error if the Y position is not given" do + graphic = described_class.new position: [50, nil], graphic_type: described_class::ELIPSE + expect { + graphic.to_zpl + }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given") + end + + + end + + +=begin + + + it "contains the barcode command '^B'" do + expect(datamatrix.to_zpl).to match /\^B/ + end + + it "contains the X position" do + expect(tokens[2]).to eq "50" + end + + it "contains the Y position" do + expect(tokens[3]).to eq "50" + end + + it "contains Data Matrix code type" do + expect(tokens[4]).to eq "^BXN" + end + + it "contains the symbol_height" do + expect(tokens[5]).to eq "5" + end + + it "contains the quality level" do + expect(tokens[6]).to eq "200" + end + + it "contains the data to be printed in the datamatrix" do + expect(tokens[8]).to eq "foobar" + end + + end +=end +end From c68f69da2b0465fc30f9713922ad77b71fffaf9b Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 13:23:02 -0400 Subject: [PATCH 08/12] Dont remove bold --- lib/zebra/zpl/text.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index 0ff7c6d..48e57c9 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -7,13 +7,17 @@ class Text class InvalidMaxLinesError < StandardError; end - attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent + attr_reader :font_size, :font_type, :width, :line_spacing, :hanging_indent, :bold def font_size=(f) FontSize.validate_font_size f @font_size = f end + def bold=(value) + @bold = value + end + def width=(width) unless (margin.nil? || margin < 1) @width = (width - (margin*2)) From bf66c88aea8284f1c5a9da0d0d16217ab7e3153e Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 13:25:38 -0400 Subject: [PATCH 09/12] remove deleted classes from required --- lib/zebra/zpl.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/zebra/zpl.rb b/lib/zebra/zpl.rb index b542f13..eee9678 100644 --- a/lib/zebra/zpl.rb +++ b/lib/zebra/zpl.rb @@ -8,8 +8,6 @@ require 'zebra/zpl/print_mode' require 'zebra/zpl/font' require 'zebra/zpl/box' -require 'zebra/zpl/diagonal' -require 'zebra/zpl/circle' require 'zebra/zpl/label' require 'zebra/zpl/text' require 'zebra/zpl/barcode' From 0983ec2ec69822326c2e6785a15f759f568d7f4f Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 13:26:50 -0400 Subject: [PATCH 10/12] remove unneccesary ws --- lib/zebra/zpl/text.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/zebra/zpl/text.rb b/lib/zebra/zpl/text.rb index 48e57c9..9051ad0 100644 --- a/lib/zebra/zpl/text.rb +++ b/lib/zebra/zpl/text.rb @@ -14,8 +14,8 @@ def font_size=(f) @font_size = f end - def bold=(value) - @bold = value + def bold=(value) + @bold = value end def width=(width) From affe026611ca99bab44378a380a2b172168ebe14 Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 16:48:45 -0400 Subject: [PATCH 11/12] Finish spec tests --- spec/zebra/zpl/graphics_spec.rb | 158 +++++++++++++++++++++++++------- 1 file changed, 126 insertions(+), 32 deletions(-) diff --git a/spec/zebra/zpl/graphics_spec.rb b/spec/zebra/zpl/graphics_spec.rb index 84ea699..def0c9b 100644 --- a/spec/zebra/zpl/graphics_spec.rb +++ b/spec/zebra/zpl/graphics_spec.rb @@ -65,19 +65,23 @@ describe "#to_zpl" do let(:valid_attributes) { { position: [50, 50], - graphic_type: Zebra::Zpl::Graphic::ELIPSE + graphic_width: 200, + graphic_height: 300, + line_thickness: 2, + color: "B", + orientation: "L" }} - let(:graphic_elipse) { described_class.new valid_attributes } - let(:graphic_diaganol) { described_class.new } - let(:graphic_box) { described_class.new } - let(:graphic_symbol) { described_class.new } - let(:graphic_circle) { described_class.new } + let(:graphic_elipse) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::ELIPSE}) } + let(:graphic_diagonal) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::DIAGONAL})} + let(:graphic_box) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::BOX}) } + let(:graphic_symbol) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::SYMBOL}) } + let(:graphic_circle) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::CIRCLE}) } - let(:tokens_elipse) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } - let(:tokens_diaganol) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } - let(:tokens_box) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } - let(:tokens_symbol) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } - let(:tokens_circle) { graphic.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_elipse) { graphic_elipse.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_diagonal) { graphic_diagonal.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_box) { graphic_box.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_symbol) { graphic_symbol.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_circle) { graphic_circle.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } it "raises an error if the X position is not given" do graphic = described_class.new position: [nil, 50], graphic_type: described_class::ELIPSE @@ -93,41 +97,131 @@ }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given") end - - end - - -=begin - - - it "contains the barcode command '^B'" do - expect(datamatrix.to_zpl).to match /\^B/ + it "raises an error if Graphic Type is not given" do + graphic = described_class.new position: [50, 50] + expect { + graphic.to_zpl + }.to raise_error(Zebra::Zpl::Graphic::InvalidGraphicType) end it "contains the X position" do - expect(tokens[2]).to eq "50" + expect(tokens_elipse[2]).to eq "50" end it "contains the Y position" do - expect(tokens[3]).to eq "50" + expect(tokens_elipse[1]).to eq "50" + end + + #Elipse Attributes + + it "elipse contains the elipse graphic command '^GE'" do + expect(tokens_elipse[3]).to eq "^GE" + end + + it "elipse contains the graphic width" do + expect(tokens_elipse[4]).to eq "200" + end + + it "elipse contains the graphic height" do + expect(tokens_elipse[5]).to eq "300" + end + + it "elipse contains the line thickness" do + expect(tokens_elipse[6]).to eq "2" + end + + it "elipse contains the color" do + expect(tokens_elipse[7]).to eq "B" + end + + #Box Attributes + + it "box contains the box graphic command '^GB'" do + expect(tokens_box[3]).to eq "^GB" + end + + it "box contains the graphic width" do + expect(tokens_box[4]).to eq "200" + end + + it "box contains the graphic height" do + expect(tokens_box[5]).to eq "300" + end + + it "box contains the line thickness" do + expect(tokens_box[6]).to eq "2" end - it "contains Data Matrix code type" do - expect(tokens[4]).to eq "^BXN" + it "box contains the color" do + expect(tokens_box[7]).to eq "B" end - it "contains the symbol_height" do - expect(tokens[5]).to eq "5" + it "box contains the orientation" do + expect(tokens_box[8]).to eq "L" end - it "contains the quality level" do - expect(tokens[6]).to eq "200" + #Circle Attributes + + it "circle contains the circle graphic command '^GC'" do + expect(tokens_circle[3]).to eq "^GC" + end + + it "circle contains the graphic width" do + expect(tokens_circle[4]).to eq "200" + end + + it "circle contains the line thickness" do + expect(tokens_circle[5]).to eq "2" + end + + it "circle contains the color" do + expect(tokens_circle[6]).to eq "B" + end + + #Diagonal Attributes + + it "diagonal contains the diagonal graphic command '^GD'" do + expect(tokens_diagonal[3]).to eq "^GD" + end + + it "diagonal contains the graphic width" do + expect(tokens_diagonal[4]).to eq "200" + end + + it "diagonal contains the graphic width" do + expect(tokens_diagonal[5]).to eq "300" + end + + it "diagonal contains the line thickness" do + expect(tokens_diagonal[6]).to eq "2" end - it "contains the data to be printed in the datamatrix" do - expect(tokens[8]).to eq "foobar" + it "diagonal contains the color" do + expect(tokens_diagonal[7]).to eq "B" end - end -=end + it "diagonal contains the orientation" do + expect(tokens_diagonal[8]).to eq "L" + end + + #Symbol Attributes + + it "symbol contains the symbol graphic command '^GS'" do + puts tokens_symbol + expect(tokens_symbol[3][0..2]).to eq "^GS" + + end + + it "symbol contains the orientation" do + expect(tokens_symbol[3][3]).to eq "L" + end + + it "symbol contains the graphic height" do + expect(tokens_symbol[4]).to eq "300" + end + + it "symbol contains the graphic width" do + expect(tokens_symbol[5]).to eq "200" + end + end end From 03ac05740f46ee7942fa1822451fd1dc382889d1 Mon Sep 17 00:00:00 2001 From: LagTag Date: Thu, 31 Oct 2019 17:04:17 -0400 Subject: [PATCH 12/12] Fix elllllllllipse --- lib/zebra/zpl/graphic.rb | 2 +- spec/zebra/zpl/graphics_spec.rb | 36 ++++++++++++++++----------------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/lib/zebra/zpl/graphic.rb b/lib/zebra/zpl/graphic.rb index eba9322..2a2a5f2 100644 --- a/lib/zebra/zpl/graphic.rb +++ b/lib/zebra/zpl/graphic.rb @@ -13,7 +13,7 @@ class InvalidGraphicType < StandardError; end attr_reader :line_thickness, :graphic_width, :graphic_height, :color, :orientation, :rounding_degree, :graphic_type attr_writer :rounding_degree - ELIPSE = "E" + ELLIPSE = "E" BOX = "B" DIAGONAL = "D" CIRCLE = "C" diff --git a/spec/zebra/zpl/graphics_spec.rb b/spec/zebra/zpl/graphics_spec.rb index def0c9b..c842dd0 100644 --- a/spec/zebra/zpl/graphics_spec.rb +++ b/spec/zebra/zpl/graphics_spec.rb @@ -2,7 +2,7 @@ describe Zebra::Zpl::Graphic do it "can be initialized with graphic type" do - graphic = described_class.new graphic_type: Zebra::Zpl::Graphic::ELIPSE + graphic = described_class.new graphic_type: Zebra::Zpl::Graphic::ELLIPSE expect(graphic.graphic_type).to eq "E" end @@ -71,27 +71,27 @@ color: "B", orientation: "L" }} - let(:graphic_elipse) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::ELIPSE}) } + let(:graphic_ellipse) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::ELLIPSE}) } let(:graphic_diagonal) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::DIAGONAL})} let(:graphic_box) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::BOX}) } let(:graphic_symbol) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::SYMBOL}) } let(:graphic_circle) { described_class.new valid_attributes.merge({graphic_type: Zebra::Zpl::Graphic::CIRCLE}) } - let(:tokens_elipse) { graphic_elipse.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } + let(:tokens_ellipse) { graphic_ellipse.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } let(:tokens_diagonal) { graphic_diagonal.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } let(:tokens_box) { graphic_box.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } let(:tokens_symbol) { graphic_symbol.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } let(:tokens_circle) { graphic_circle.to_zpl.split(/(\^[A-Z]+|\,)/).reject{ |e| ['', ',', nil].include?(e) } } it "raises an error if the X position is not given" do - graphic = described_class.new position: [nil, 50], graphic_type: described_class::ELIPSE + graphic = described_class.new position: [nil, 50], graphic_type: described_class::ELLIPSE expect { graphic.to_zpl }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the X value is not given") end it "raises an error if the Y position is not given" do - graphic = described_class.new position: [50, nil], graphic_type: described_class::ELIPSE + graphic = described_class.new position: [50, nil], graphic_type: described_class::ELLIPSE expect { graphic.to_zpl }.to raise_error(Zebra::Zpl::Printable::MissingAttributeError, "Can't print if the Y value is not given") @@ -105,33 +105,33 @@ end it "contains the X position" do - expect(tokens_elipse[2]).to eq "50" + expect(tokens_ellipse[2]).to eq "50" end it "contains the Y position" do - expect(tokens_elipse[1]).to eq "50" + expect(tokens_ellipse[1]).to eq "50" end #Elipse Attributes - it "elipse contains the elipse graphic command '^GE'" do - expect(tokens_elipse[3]).to eq "^GE" + it "ellipse contains the ellipse graphic command '^GE'" do + expect(tokens_ellipse[3]).to eq "^GE" end - it "elipse contains the graphic width" do - expect(tokens_elipse[4]).to eq "200" + it "ellipse contains the graphic width" do + expect(tokens_ellipse[4]).to eq "200" end - it "elipse contains the graphic height" do - expect(tokens_elipse[5]).to eq "300" + it "ellipse contains the graphic height" do + expect(tokens_ellipse[5]).to eq "300" end - it "elipse contains the line thickness" do - expect(tokens_elipse[6]).to eq "2" + it "ellipse contains the line thickness" do + expect(tokens_ellipse[6]).to eq "2" end - it "elipse contains the color" do - expect(tokens_elipse[7]).to eq "B" + it "ellipse contains the color" do + expect(tokens_ellipse[7]).to eq "B" end #Box Attributes @@ -207,9 +207,7 @@ #Symbol Attributes it "symbol contains the symbol graphic command '^GS'" do - puts tokens_symbol expect(tokens_symbol[3][0..2]).to eq "^GS" - end it "symbol contains the orientation" do