Module: Rdpl::Element
- Included in:
- Barcode, BitmappedText, LinesAndBoxes
- Defined in:
- lib/elements/element.rb
Defined Under Namespace
Classes: FixedValueError, InvalidAssigmentError, InvalidBarcodeHeightError, InvalidFontIdError, InvalidHeightMultiplierError, InvalidRotationError, InvalidWidthMultiplierError
Constant Summary collapse
- ROTATION_0_DEGREES =
1
- ROTATION_90_DEGREES =
2
- ROTATION_180_DEGREES =
3
- ROTATION_270_DEGREES =
4
Instance Method Summary collapse
- #column_position ⇒ Object
-
#column_position=(position) ⇒ Object
Interpreted in hundredths of an inch or tenths of millimeters, depending on the measurement used in the printing job.
- #data ⇒ Object
- #data=(data) ⇒ Object
- #font_id ⇒ Object
-
#font_id=(font_id) ⇒ Object
Sets the element font type.
-
#formatted_height ⇒ Object
Used only by barcode and smooth/scalable fonts, but has to be present as 000 in other elements.
-
#height_multiplier ⇒ Object
Returns the specified height multiplier.
-
#height_multiplier=(multiplier) ⇒ Object
Valid values goes from 1 to 9 and A to O (base 25).
-
#initialize(options = {}) ⇒ Object
Initializes a new element.
- #rotation ⇒ Object
-
#rotation=(rotation) ⇒ Object
Sets the element’s rotation angle.
- #row_position ⇒ Object
-
#row_position=(position) ⇒ Object
Interpreted in hundreths of an inch or tenths of millimeters, depending on the measurement used in the printing job.
- #to_s ⇒ Object
-
#width_multiplier ⇒ Object
Returns the specified width multiplier.
-
#width_multiplier=(multiplier) ⇒ Object
Valid values goes from 1 to 9 and A to O (base 25).
Instance Method Details
#column_position ⇒ Object
110 111 112 |
# File 'lib/elements/element.rb', line 110 def column_position @column_position || 0 end |
#column_position=(position) ⇒ Object
Interpreted in hundredths of an inch or tenths of millimeters, depending on the measurement used in the printing job.
Notice that the limits for this value depend on the printer model.
106 107 108 |
# File 'lib/elements/element.rb', line 106 def column_position=(position) @column_position = position end |
#data ⇒ Object
118 119 120 |
# File 'lib/elements/element.rb', line 118 def data @data || '' end |
#data=(data) ⇒ Object
114 115 116 |
# File 'lib/elements/element.rb', line 114 def data=(data) @data = data end |
#font_id ⇒ Object
60 61 62 |
# File 'lib/elements/element.rb', line 60 def font_id @font_id end |
#font_id=(font_id) ⇒ Object
Sets the element font type. Available types are:
-
Type Interpretation
-
0-9 Font
-
A-T Barcode with human readable text
-
a-z Barcode without human readable text
-
X Line, box, polygon, circle
-
Y Image
55 56 57 58 |
# File 'lib/elements/element.rb', line 55 def font_id=(font_id) raise InvalidFontIdError unless valid_font_id_ranges.any? { |range| range.include? font_id } @font_id = font_id end |
#formatted_height ⇒ Object
Used only by barcode and smooth/scalable fonts, but has to be present as 000 in other elements.
88 89 90 |
# File 'lib/elements/element.rb', line 88 def formatted_height '000' end |
#height_multiplier ⇒ Object
Returns the specified height multiplier. Defaults to 1.
82 83 84 |
# File 'lib/elements/element.rb', line 82 def height_multiplier @height_multiplier || 1 end |
#height_multiplier=(multiplier) ⇒ Object
Valid values goes from 1 to 9 and A to O (base 25)
76 77 78 79 |
# File 'lib/elements/element.rb', line 76 def height_multiplier=(multiplier) raise InvalidHeightMultiplierError, multiplier unless valid_width_or_height_multiplier?(multiplier) @height_multiplier = multiplier end |
#initialize(options = {}) ⇒ Object
Initializes a new element. Available options are:
-
:rotation
the element’s rotation. -
:font_id
the element’s font id. Can go from ‘a’ to ‘z’ or ‘A’ to ‘Z’ for barcodes or from ‘0’ to ‘9’ for bitmapped fonts. -
:data
the data to be printed or encoded, usually some text. -
:height
the element’s height. Can go from 0 to 999 for barcodes or any other value for another kind of element. -
:row_position
the vertical position of the element inside the label, in hundredths of an inch or tenths of a millimeter. -
:column_position
the horizontal position of the element inside the label, in hundredths of an inch or tenths of a millimeter. -
:bottom_and_top_thickness
defines the thickness of bottom and top box edges. Used only forRdpl::Element::Box
. -
:sides_thickness
defines the thickness of the box sides. Used only forRdpl::Element::Box
. -
:width_multiplier
-
:height_multiplier
27 28 29 |
# File 'lib/elements/element.rb', line 27 def initialize( = {}) .each_pair { |option, value| self.send "#{option}=", value } end |
#rotation ⇒ Object
43 44 45 |
# File 'lib/elements/element.rb', line 43 def rotation @rotation || ROTATION_0_DEGREES end |
#rotation=(rotation) ⇒ Object
Sets the element’s rotation angle. Can be one of the following constants:
-
Rdpl::Element::ROTATION_0_DEGREES
-
Rdpl::Element::ROTATION_90_DEGREES
-
Rdpl::Element::ROTATION_180_DEGREES
-
Rdpl::Element::ROTATION_270_DEGREES
Raises Rdpl::Element::InvalidRotationError
if passed a value different from these constants.
38 39 40 41 |
# File 'lib/elements/element.rb', line 38 def rotation=(rotation) raise InvalidRotationError, rotation unless valid_rotation_range.include?(rotation) @rotation = rotation end |
#row_position ⇒ Object
98 99 100 |
# File 'lib/elements/element.rb', line 98 def row_position @row_position || 0 end |
#row_position=(position) ⇒ Object
Interpreted in hundreths of an inch or tenths of millimeters, depending on the measurement used in the printing job.
94 95 96 |
# File 'lib/elements/element.rb', line 94 def row_position=(position) @row_position = position end |
#to_s ⇒ Object
122 123 124 125 |
# File 'lib/elements/element.rb', line 122 def to_s [rotation, font_id, width_multiplier, height_multiplier, formatted_height, formatted_row_position, formatted_column_position, data].join end |
#width_multiplier ⇒ Object
Returns the specified width multiplier. Defaults to 1.
71 72 73 |
# File 'lib/elements/element.rb', line 71 def width_multiplier @width_multiplier || 1 end |
#width_multiplier=(multiplier) ⇒ Object
Valid values goes from 1 to 9 and A to O (base 25)
65 66 67 68 |
# File 'lib/elements/element.rb', line 65 def width_multiplier=(multiplier) raise InvalidWidthMultiplierError, multiplier unless valid_width_or_height_multiplier?(multiplier) @width_multiplier = multiplier end |