Class: Alchemrest::Transforms::ToDecimal

Inherits:
Morpher::Transform
  • Object
show all
Defined in:
lib/alchemrest/transforms/to_decimal.rb

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object



6
7
8
9
10
# File 'lib/alchemrest/transforms/to_decimal.rb', line 6

def call(input)
  success(BigDecimal(input, 0))
rescue TypeError, ArgumentError
  cannot_make_decimal(input)
end

#cannot_make_decimal(input) ⇒ Object



12
13
14
15
16
17
18
19
# File 'lib/alchemrest/transforms/to_decimal.rb', line 12

def cannot_make_decimal(input)
  failure(
    error(
      message: "Expected #{input} to be castable to BigDecimal",
      input:,
    ),
  )
end