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

Instance Method Details

#column_positionObject



90
91
92
# File 'lib/elements/element.rb', line 90

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.



86
87
88
# File 'lib/elements/element.rb', line 86

def column_position=(position)
  @column_position = position
end

#dataObject



98
99
100
# File 'lib/elements/element.rb', line 98

def data
  @data || ''
end

#data=(data) ⇒ Object



94
95
96
# File 'lib/elements/element.rb', line 94

def data=(data)
  @data = data
end

#font_idObject



42
43
44
# File 'lib/elements/element.rb', line 42

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

Raises:



37
38
39
40
# File 'lib/elements/element.rb', line 37

def font_id=(font_id)
  raise InvalidFontIdError unless valid_font_id_ranges.any? { |range| range.include? font_id }
  @font_id = font_id
end

#formatted_heightObject

Used only by barcode and smooth/scaleble fonts, but has to be present as 000 in other elements.



68
69
70
# File 'lib/elements/element.rb', line 68

def formatted_height
  '000'
end

#height_multiplierObject

Valid values goes from 1 to 9 and A to O (base 25)



62
63
64
# File 'lib/elements/element.rb', line 62

def height_multiplier
  @height_multiplier || 1
end

#height_multiplier=(multiplier) ⇒ Object



56
57
58
59
# File 'lib/elements/element.rb', line 56

def height_multiplier=(multiplier)
  raise InvalidHeightMultiplierError, multiplier unless valid_width_or_height_multiplier?(multiplier)
  @height_multiplier = multiplier
end

#initialize(options = {}) ⇒ Object



16
17
18
# File 'lib/elements/element.rb', line 16

def initialize(options = {})
  options.each_pair { |option, value| self.send "#{option}=", value }
end

#rotationObject



25
26
27
# File 'lib/elements/element.rb', line 25

def rotation
  @rotation || ROTATION_0_DEGREES
end

#rotation=(rotation) ⇒ Object



20
21
22
23
# File 'lib/elements/element.rb', line 20

def rotation=(rotation)
  raise InvalidRotationError, rotation unless valid_rotation_range.include?(rotation)
  @rotation = rotation
end

#row_positionObject



78
79
80
# File 'lib/elements/element.rb', line 78

def row_position
  @row_position || 0
end

#row_position=(position) ⇒ Object

Interpreted in hundredths of an inch or tenths of millimeters, depending on the measurement used in the printing job.



74
75
76
# File 'lib/elements/element.rb', line 74

def row_position=(position)
  @row_position = position   
end

#to_sObject



102
103
104
105
# File 'lib/elements/element.rb', line 102

def to_s
  [rotation, font_id, width_multiplier, height_multiplier, formatted_height, 
    formatted_row_position, formatted_column_position, data].join
end

#width_multiplierObject



52
53
54
# File 'lib/elements/element.rb', line 52

def width_multiplier
  @width_multiplier || 1
end

#width_multiplier=(multiplier) ⇒ Object

Valid values goes from 1 to 9 and A to O (base 25)



47
48
49
50
# File 'lib/elements/element.rb', line 47

def width_multiplier=(multiplier)
  raise InvalidWidthMultiplierError, multiplier unless valid_width_or_height_multiplier?(multiplier)
  @width_multiplier = multiplier
end