Module: NtiReceiptBuilder::TypeInference

Defined in:
lib/nti_receipt_builder/type_inference.rb

Overview

Maps a resolved value to the formatting type used by VariableResolver and the collection presenter. Inference is the default so a host declares nothing for the common cases; a Variables subclass overrides it per key with variable KEY, type: :currency.

Deciding at format time rather than declaration time means real data and preview samples travel the same path.

Class Method Summary collapse

Class Method Details

.call(value) ⇒ Object



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

def call(value)
  case value
  when nil then nil
  when Array then :collection
  when BigDecimal then :currency
  when Numeric then :number
  else
    value.respond_to?(:strftime) ? :datetime : :string
  end
end