Class: ActsAsCalculatorEditor::BuildSampleResult

Inherits:
Object
  • Object
show all
Defined in:
lib/acts_as_calculator_editor/build_sample_result.rb

Overview

Something for {{ result.value }} to be, while the author is still typing the template.

ActsAsCalculator::Result is a plain Data.define, and CastLiquidValue wraps whatever it is handed in a ResultDrop on the way into the template — so a preview needs no run, no formula version and no database row (docs/core-gem-contract.md §4.3). formula_version is left nil deliberately: {{ result.formula_version }} in a preview should read as empty rather than as some arbitrary row the author did not choose.

Constant Summary collapse

DEFAULT_VALUE =
"41250.5"
DEFAULT_INPUTS =
{ "salary" => 50_000, "tax" => 8_749.5 }.freeze

Class Method Summary collapse

Class Method Details

.call(value: DEFAULT_VALUE, inputs: DEFAULT_INPUTS, expression: "salary - tax", as_of: nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/acts_as_calculator_editor/build_sample_result.rb', line 15

def self.call(value: DEFAULT_VALUE, inputs: DEFAULT_INPUTS, expression: "salary - tax", as_of: nil)
  value = ActsAsCalculator::CastDecimal.(value)

  ActsAsCalculator::Result.new(
    value:,
    breakdown: { expression:, inputs: inputs.to_h, value: },
    formula_version: nil,
    as_of: as_of || Date.current
  )
end