Class: NtiReceiptBuilder::Presenters::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/nti_receipt_builder/presenters/element.rb

Overview

Presents one variable or text layout element: a whitelisted inline style string and a plain (un-escaped-by-us) display string. ERB's default auto-escaping in the render partials is what actually escapes the text — this presenter never marks anything html_safe.

Instance Method Summary collapse

Constructor Details

#initialize(element, resolved_variables) ⇒ Element

Returns a new instance of Element.



10
11
12
13
# File 'lib/nti_receipt_builder/presenters/element.rb', line 10

def initialize(element, resolved_variables)
  @element = element
  @resolved_variables = resolved_variables
end

Instance Method Details

#css_styleObject



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nti_receipt_builder/presenters/element.rb', line 23

def css_style
  declarations = [
    'position: absolute',
    "left: #{x_mm}mm",
    "top: #{y_mm}mm",
    "width: #{width_mm}mm",
    "height: #{height_mm}mm",
    "z-index: #{z_index}"
  ]
  declarations.concat(style_declarations).join('; ')
end

#display_textObject



35
36
37
38
39
40
# File 'lib/nti_receipt_builder/presenters/element.rb', line 35

def display_text
  case type
  when 'variable' then variable_display_text
  when 'text' then element['text'].to_s
  end
end

#height_mmObject



20
# File 'lib/nti_receipt_builder/presenters/element.rb', line 20

def height_mm = element['height_mm'].to_f

#idObject



15
# File 'lib/nti_receipt_builder/presenters/element.rb', line 15

def id = element['id']

#typeObject



16
# File 'lib/nti_receipt_builder/presenters/element.rb', line 16

def type = element['type']

#width_mmObject



19
# File 'lib/nti_receipt_builder/presenters/element.rb', line 19

def width_mm = element['width_mm'].to_f

#x_mmObject



17
# File 'lib/nti_receipt_builder/presenters/element.rb', line 17

def x_mm = element['x_mm'].to_f

#y_mmObject



18
# File 'lib/nti_receipt_builder/presenters/element.rb', line 18

def y_mm = element['y_mm'].to_f

#z_indexObject



21
# File 'lib/nti_receipt_builder/presenters/element.rb', line 21

def z_index = element['z_index'] || 0