Class: Rdpl::Label
Overview
Represents a label to be printed. Labels must me included in an instance of Rdpl::Job
.
Constant Summary collapse
- START =
'L'
- FINISH =
'E'
- DEFAULT_DOT_SIZE =
11
- DEFAULT_HEAT =
14
Instance Attribute Summary collapse
-
#job ⇒ Object
writeonly
Sets the attribute job.
-
#quantity ⇒ Object
readonly
Returns the value of attribute quantity.
-
#state ⇒ Object
readonly
Returns the value of attribute state.
Instance Method Summary collapse
-
#<<(arg) ⇒ Object
Adds a new element to this label.
-
#[](arg) ⇒ Object
:nodoc:.
-
#dot_size ⇒ Object
Returns the current dot size.
-
#dump ⇒ Object
Dumps this label’s contents to a string.
-
#end! ⇒ Object
Closes this label for edition.
-
#heat ⇒ Object
Returns the current heat setting to be used when printing.
-
#initialize(options = {}) ⇒ Label
constructor
Creates a new instance of
Rdpl::Label
. -
#mm? ⇒ Boolean
Returns
true
if this label’s job is setted to use millimeters as measurement unit. -
#start_of_print ⇒ Object
Returns the start of print position for the label.
Methods included from Commandable
Constructor Details
#initialize(options = {}) ⇒ Label
Creates a new instance of Rdpl::Label
Available options are:
-
:heat
the heat setting to be used when printing this label. This is optional and defaults to 14. -
:dot_size
the dot size to be used when printing this label. This is optional and defaults to 11. -
:start_of_print
the inicial position to start printing the label. This is optional and has no default value, since this setting depends on the printer model. -
:quantity
the number of copies of this label to be printed.
22 23 24 25 |
# File 'lib/label.rb', line 22 def initialize( = {}) @contents = '' start end |
Instance Attribute Details
#job=(value) ⇒ Object (writeonly)
Sets the attribute job
5 6 7 |
# File 'lib/label.rb', line 5 def job=(value) @job = value end |
#quantity ⇒ Object (readonly)
Returns the value of attribute quantity.
4 5 6 |
# File 'lib/label.rb', line 4 def quantity @quantity end |
#state ⇒ Object (readonly)
Returns the value of attribute state.
4 5 6 |
# File 'lib/label.rb', line 4 def state @state end |
Instance Method Details
#<<(arg) ⇒ Object
Adds a new element to this label. An element can be one of the following:
-
Rdpl::Barcode
-
Rdpl::BitmappedText
-
Rdpl::Box
-
Rdpl::Line
-
A simple string containing DPL commands
51 52 53 54 |
# File 'lib/label.rb', line 51 def <<(arg) raise EndedElementError unless state == :open @contents << arg.to_s << NEW_LINE end |
#[](arg) ⇒ Object
:nodoc:
40 41 42 |
# File 'lib/label.rb', line 40 def [](arg) # :nodoc: @contents[arg] end |
#dot_size ⇒ Object
Returns the current dot size.
57 58 59 |
# File 'lib/label.rb', line 57 def dot_size @dot_size || DEFAULT_DOT_SIZE end |
#dump ⇒ Object
Dumps this label’s contents to a string.
28 29 30 |
# File 'lib/label.rb', line 28 def dump @contents.dup end |
#end! ⇒ Object
Closes this label for edition. This appends DPL specific commands to the label, so the printer knows where the printing must end and where another label is started.
34 35 36 37 38 |
# File 'lib/label.rb', line 34 def end! self << formatted_quantity unless quantity.nil? self << FINISH self.state = :finished end |
#heat ⇒ Object
Returns the current heat setting to be used when printing.
62 63 64 |
# File 'lib/label.rb', line 62 def heat @heat || DEFAULT_HEAT end |
#mm? ⇒ Boolean
Returns true
if this label’s job is setted to use millimeters as measurement unit. I the label does not have a job yet, it will return false
.
68 69 70 |
# File 'lib/label.rb', line 68 def mm? @job ? @job.mm? : false end |
#start_of_print ⇒ Object
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.
77 78 79 80 |
# File 'lib/label.rb', line 77 def start_of_print return nil if @start_of_print.nil? @start_of_print.to_f / (mm? ? 10 : 100) end |