Sha256: 7b50cde34c3e62683fa95388d6ec58321b207cd622f261fdb7dc55b5b637a6d1

Contents?: true

Size: 1.01 KB

Versions: 5

Compression:

Stored size: 1.01 KB

Contents

module Zebra
  module Epl
    module Printable
      class MissingAttributeError < StandardError
        def initialize(message)
          super("Can't print if #{message}")
        end
      end

      attr_reader :position, :x, :y
      attr_accessor :data

      def initialize(options = {})
        options.each_pair { |attribute, value| self.__send__ "#{attribute}=", value }
      end

      def position=(coords)
        @position, @x, @y = coords, coords[0], coords[1]
      end

      def rotation=(rot)
        Rotation.validate_rotation rot
        @rotation = rot
      end

      def rotation
        @rotation || Rotation::NO_ROTATION
      end

      private

      def has_data?
        true
      end

      def check_attributes
        raise MissingAttributeError.new("the X value is not given") unless @x
        raise MissingAttributeError.new("the Y value is not given") unless @y
        raise MissingAttributeError.new("the data to be printed is not given") unless @data || !has_data?
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
zebra-epl-0.0.8 lib/zebra/epl/printable.rb
zebra-epl-0.0.7 lib/zebra/epl/printable.rb
zebra-epl-0.0.6 lib/zebra/epl/printable.rb
zebra-epl-0.0.5 lib/zebra/epl/printable.rb
zebra-epl-0.0.2 lib/zebra/epl/printable.rb