Class: Virtus::Coercion::Decimal

Inherits:
Numeric show all
Defined in:
lib/virtus/coercion/decimal.rb

Overview

Coerce BigDecimal values

Constant Summary collapse

FLOAT_FORMAT =
'F'.freeze

Constants inherited from Object

Object::COERCION_METHOD_REGEXP

Constants included from TypeLookup

TypeLookup::TYPE_FORMAT

Class Method Summary collapse

Methods inherited from Numeric

to_float, to_integer

Methods inherited from Object

to_array, to_hash, to_integer

Methods inherited from Virtus::Coercion

[]

Methods included from TypeLookup

#determine_type, extended, #primitive

Methods included from Options

#accept_options, #accepted_options, #options

Class Method Details

.to_decimal(value) ⇒ Fixnum

Passthrough the value

Examples:

Virtus::Coercion::BigDecimal.to_decimal(BigDecimal('1.0')) # => BigDecimal('1.0')

Parameters:

  • value (BigDecimal)

Returns:

  • (Fixnum)


34
35
36
# File 'lib/virtus/coercion/decimal.rb', line 34

def self.to_decimal(value)
  value
end

.to_string(value) ⇒ String

Coerce given value to String

Examples:

Virtus::Coercion::BigDecimal.to_string(BigDecimal('1.0')) # => "1.0"

Parameters:

  • value (BigDecimal)

Returns:



20
21
22
# File 'lib/virtus/coercion/decimal.rb', line 20

def self.to_string(value)
  value.to_s(FLOAT_FORMAT)
end