Class: Stockboy::Translations::Decimal

Inherits:
Stockboy::Translator show all
Defined in:
lib/stockboy/translations/decimal.rb

Overview

Convert numeric strings to BigDecimal

Job template DSL

Registered as :decimal. Use with:

attributes do
  check_in as: :decimal
end

Examples:

dec = Stockboy::Translator::Date.new

record.cost = "256.99"
dec.translate(record, :cost) # => #<BigDecimal 256.99>

Instance Attribute Summary

Attributes inherited from Stockboy::Translator

#field_key

Instance Method Summary collapse

Methods inherited from Stockboy::Translator

#call, #initialize, #inspect

Constructor Details

This class inherits a constructor from Stockboy::Translator

Instance Method Details

#translate(context) ⇒ BigDecimal

Returns:

  • (BigDecimal)


25
26
27
28
29
30
# File 'lib/stockboy/translations/decimal.rb', line 25

def translate(context)
  value = field_value(context, field_key)
  return nil if value.blank?

  BigDecimal.new(value, 10)
end