Class: Zebra::Epl::Label
- Inherits:
-
Object
- Object
- Zebra::Epl::Label
- Defined in:
- lib/zebra/epl/label.rb
Defined Under Namespace
Classes: InvalidPrintDensityError, InvalidPrintSpeedError, PrintSpeedNotInformedError
Instance Attribute Summary collapse
- #copies ⇒ Object
-
#elements ⇒ Object
readonly
Returns the value of attribute elements.
-
#gap ⇒ Object
Returns the value of attribute gap.
-
#length ⇒ Object
Returns the value of attribute length.
-
#print_density ⇒ Object
Returns the value of attribute print_density.
-
#print_speed ⇒ Object
Returns the value of attribute print_speed.
-
#tempfile ⇒ Object
readonly
Returns the value of attribute tempfile.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #<<(element) ⇒ Object
- #dump_contents(io = STDOUT) ⇒ Object
-
#initialize(options = {}) ⇒ Label
constructor
A new instance of Label.
- #length_and_gap=(length_and_gap) ⇒ Object
- #persist ⇒ Object
- #persisted? ⇒ Boolean
Constructor Details
#initialize(options = {}) ⇒ Label
Returns a new instance of Label.
14 15 16 17 |
# File 'lib/zebra/epl/label.rb', line 14 def initialize( = {}) .each_pair { |key, value| self.__send__("#{key}=", value) if self.respond_to?("#{key}=") } @elements = [] end |
Instance Attribute Details
#copies ⇒ Object
34 35 36 |
# File 'lib/zebra/epl/label.rb', line 34 def copies @copies || 1 end |
#elements ⇒ Object (readonly)
Returns the value of attribute elements.
11 12 13 |
# File 'lib/zebra/epl/label.rb', line 11 def elements @elements end |
#gap ⇒ Object
Returns the value of attribute gap.
12 13 14 |
# File 'lib/zebra/epl/label.rb', line 12 def gap @gap end |
#length ⇒ Object
Returns the value of attribute length.
12 13 14 |
# File 'lib/zebra/epl/label.rb', line 12 def length @length end |
#print_density ⇒ Object
Returns the value of attribute print_density.
12 13 14 |
# File 'lib/zebra/epl/label.rb', line 12 def print_density @print_density end |
#print_speed ⇒ Object
Returns the value of attribute print_speed.
12 13 14 |
# File 'lib/zebra/epl/label.rb', line 12 def print_speed @print_speed end |
#tempfile ⇒ Object (readonly)
Returns the value of attribute tempfile.
11 12 13 |
# File 'lib/zebra/epl/label.rb', line 11 def tempfile @tempfile end |
#width ⇒ Object
Returns the value of attribute width.
12 13 14 |
# File 'lib/zebra/epl/label.rb', line 12 def width @width end |
Instance Method Details
#<<(element) ⇒ Object
38 39 40 |
# File 'lib/zebra/epl/label.rb', line 38 def <<(element) elements << element end |
#dump_contents(io = STDOUT) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/zebra/epl/label.rb', line 42 def dump_contents(io = STDOUT) check_required_configurations # Start options io << "O\n" # Q<label height in dots>,<space between labels in dots> io << "Q#{length},#{gap}\n" if length && gap # q<label width in dots> io << "q#{width}\n" if width # Print Speed (S command) io << "S#{print_speed}\n" # Density (D command) io << "D#{print_density}\n" if print_density # ZT = Printing from top of image buffer. io << "\n" # Start new label io << "N\n" elements.each do |element| io << element.to_epl << "\n" end io << "P#{copies}\n" end |
#length_and_gap=(length_and_gap) ⇒ Object
19 20 21 22 |
# File 'lib/zebra/epl/label.rb', line 19 def length_and_gap=(length_and_gap) self.length = length_and_gap[0] self.gap = length_and_gap[1] end |
#persist ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/zebra/epl/label.rb', line 67 def persist tempfile = Tempfile.new "zebra_label" dump_contents tempfile tempfile.close @tempfile = tempfile tempfile end |
#persisted? ⇒ Boolean
75 76 77 |
# File 'lib/zebra/epl/label.rb', line 75 def persisted? !!self.tempfile end |