Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consolidate Graphic Elements to One Class #42

Merged
merged 14 commits into from
Oct 31, 2019
3 changes: 1 addition & 2 deletions lib/zebra/zpl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -19,4 +17,5 @@
require 'zebra/zpl/pdf417'
require 'zebra/zpl/justification'
require 'zebra/zpl/raw'
require 'zebra/zpl/graphic'
require 'zebra/zpl/datamatrix'
1 change: 1 addition & 0 deletions lib/zebra/zpl/box.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 0 additions & 44 deletions lib/zebra/zpl/circle.rb

This file was deleted.

55 changes: 0 additions & 55 deletions lib/zebra/zpl/diagonal.rb

This file was deleted.

79 changes: 79 additions & 0 deletions lib/zebra/zpl/graphic.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
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

attr_reader :line_thickness, :graphic_width, :graphic_height, :color, :orientation, :rounding_degree, :graphic_type
attr_writer :rounding_degree

ELLIPSE = "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 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 %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
zpl = case graphic_type
when "B"
"B#{graphic_width},#{graphic_height},#{line_thickness},#{color},#{orientation}"
when "E"
"E#{graphic_width},#{graphic_height},#{line_thickness},#{color}"
when "C"
"C#{graphic_width},#{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
raise InvalidGraphicType if @graphic_type.nil?
end
end
end
end
Loading