Skip to content

Commit

Permalink
Merge pull request #31 from LagTag/circle_graphic
Browse files Browse the repository at this point in the history
Circle Graphic (^GC)
  • Loading branch information
mtking2 authored Oct 14, 2019
2 parents 681bba2 + 09edeb6 commit 915ff85
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/zebra/zpl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
require 'zebra/zpl/print_mode'
require 'zebra/zpl/font'
require 'zebra/zpl/box'
require 'zebra/zpl/circle'
require 'zebra/zpl/label'
require 'zebra/zpl/text'
require 'zebra/zpl/barcode'
Expand Down
44 changes: 44 additions & 0 deletions lib/zebra/zpl/circle.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
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 value&.upcase.in?(["B","W"])
@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

0 comments on commit 915ff85

Please sign in to comment.