Class: NtiReceiptBuilder::VariableResolver
- Inherits:
-
Object
- Object
- NtiReceiptBuilder::VariableResolver
- Includes:
- ActionView::Helpers::NumberHelper
- Defined in:
- lib/nti_receipt_builder/variable_resolver.rb
Overview
Resolves every scalar variable to a formatted (not yet escaped) string. Missing keys resolve to nil so presenters can apply their own fallback.
A declared type wins; otherwise the value's class decides. Collection variables are skipped — the collection presenter formats its own cells.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(data, definitions:) ⇒ VariableResolver
constructor
A new instance of VariableResolver.
Constructor Details
#initialize(data, definitions:) ⇒ VariableResolver
Returns a new instance of VariableResolver.
14 15 16 17 |
# File 'lib/nti_receipt_builder/variable_resolver.rb', line 14 def initialize(data, definitions:) @data = data || {} @definitions = definitions end |
Instance Method Details
#call ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/nti_receipt_builder/variable_resolver.rb', line 19 def call definitions.each_with_object({}) do |(key, definition), resolved| next if definition.collection? resolved[key] = format_value(definition, data[key]) end end |