Class: NtiReceiptBuilder::TemplateForm
- Inherits:
-
Object
- Object
- NtiReceiptBuilder::TemplateForm
- Includes:
- ActiveModel::Model
- Defined in:
- lib/nti_receipt_builder/template_form.rb
Overview
Validates and coerces submitted template params.
layout arrives as a JSON string from the builder's hidden field. Unparseable JSON is
rejected rather than silently dropped — a designer whose layout failed to serialise must
see an error, not a blank receipt.
Constant Summary collapse
- ATTRIBUTES =
%i[name paper_size_key paper_width_mm paper_height_mm orientation height_mode margin_top_mm margin_right_mm margin_bottom_mm margin_left_mm layout lock_version].freeze
Instance Method Summary collapse
Instance Method Details
#attributes ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nti_receipt_builder/template_form.rb', line 25 def attributes { name: name, paper_size_key: paper_size_key, paper_width_mm: paper_width_mm, paper_height_mm: paper_height_mm, orientation: orientation, height_mode: height_mode, margin_top_mm: margin_top_mm.presence || 0, margin_right_mm: margin_right_mm.presence || 0, margin_bottom_mm: margin_bottom_mm.presence || 0, margin_left_mm: margin_left_mm.presence || 0, layout: parsed_layout }.tap { |attrs| attrs[:lock_version] = lock_version if lock_version.present? } end |
#parsed_layout ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/nti_receipt_builder/template_form.rb', line 41 def parsed_layout return [] if layout.blank? return layout if layout.is_a?(Array) JSON.parse(layout) rescue JSON::ParserError [] end |