class Labelary::Label

Public Class Methods

new(dpmm: nil, width: nil, height: nil, index: nil, zpl:, content_type: nil, font: nil) click to toggle source
# File lib/labelary/label.rb, line 7
def initialize(dpmm: nil, width: nil, height: nil, index: nil, zpl:, content_type: nil, font: nil)
  @zpl    ||= zpl
  @dpmm   ||= dpmm   || config.dpmm
  @width  ||= width  || config.width
  @height ||= height || config.height
  @index  ||= index  || config.index
  @content_type ||= content_type || config.content_type
  @font ||= font || config.font

  raise 'Invalid dpmm'   if @dpmm.nil?
  raise 'Invalid width'  if @width.nil?
  raise 'Invalid height' if @height.nil?
end
render(*args) click to toggle source
# File lib/labelary/label.rb, line 3
def self.render(*args)
  self.new(*args).render
end

Public Instance Methods

font_string() click to toggle source
# File lib/labelary/label.rb, line 28
def font_string
  @font.present? ? @font.to_s : ''
end
render() click to toggle source

labelary.com/service.html

# File lib/labelary/label.rb, line 22
def render
  payload = font_string + @zpl
  response = Labelary::Client.connection.post "/v1/printers/#{@dpmm}dpmm/labels/#{@width}x#{@height}/#{@index}/", payload, { Accept: @content_type }
  return response.body
end

Private Instance Methods

config() click to toggle source
# File lib/labelary/label.rb, line 34
def config
  @config ||= Labelary.configuration
end