Class: Rdpl::Label

Inherits:
Object
  • Object
show all
Includes:
Commandable
Defined in:
lib/label.rb

Constant Summary collapse

START =
'L'
FINISH =
'E'
DEFAULT_DOT_SIZE =
11
DEFAULT_HEAT =
14

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Commandable

#command

Constructor Details

#initialize(options = {}) ⇒ Label

Returns a new instance of Label.



13
14
15
16
# File 'lib/label.rb', line 13

def initialize(options = {})
  @contents = ''
  start options
end

Instance Attribute Details

#job=(value) ⇒ Object (writeonly)

Sets the attribute job

Parameters:

  • value

    the value to set the attribute job to.



4
5
6
# File 'lib/label.rb', line 4

def job=(value)
  @job = value
end

#quantityObject (readonly)

Returns the value of attribute quantity.



3
4
5
# File 'lib/label.rb', line 3

def quantity
  @quantity
end

#stateObject (readonly)

Returns the value of attribute state.



3
4
5
# File 'lib/label.rb', line 3

def state
  @state
end

Instance Method Details

#<<(arg) ⇒ Object

Raises:



32
33
34
35
# File 'lib/label.rb', line 32

def <<(arg)
  raise EndedElementError unless state == :open
  @contents << arg.to_s << NEW_LINE
end

#[](arg) ⇒ Object



28
29
30
# File 'lib/label.rb', line 28

def [](arg)
  @contents[arg]
end

#dot_sizeObject



37
38
39
# File 'lib/label.rb', line 37

def dot_size
  @dot_size || DEFAULT_DOT_SIZE
end

#dumpObject



18
19
20
# File 'lib/label.rb', line 18

def dump
  @contents.dup
end

#end!Object



22
23
24
25
26
# File 'lib/label.rb', line 22

def end!
  self << formatted_quantity unless quantity.nil?
  self << FINISH 
  self.state = :finished
end

#heatObject



41
42
43
# File 'lib/label.rb', line 41

def heat
  @heat || DEFAULT_HEAT
end

#mm?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/label.rb', line 45

def mm?
  @job ? @job.mm? : false
end

#start_of_printObject

Returns the start of print position for the label. If the option wasn’t specified in the label’s constructor, nil will be returned and the printer will assume the default start of print.

It works this way since the default value for this parameter depends on the printer’s model.



54
55
56
57
# File 'lib/label.rb', line 54

def start_of_print
  return nil if @start_of_print.nil?
  @start_of_print.to_f / (mm? ? 10 : 100)
end