Class: Virtus::Coercion::Integer

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

Overview

Coerce Fixnum values

Constant Summary

Constants inherited from Object

Object::COERCION_METHOD_REGEXP

Constants included from TypeLookup

TypeLookup::EXTRA_CONST_ARGS, TypeLookup::TYPE_FORMAT

Class Method Summary collapse

Methods inherited from Numeric

to_decimal, to_float

Methods inherited from Object

method_missing

Methods inherited from Virtus::Coercion

[]

Methods included from DescendantsTracker

#add_descendant, #descendants

Methods included from TypeLookup

#determine_type, #primitive

Methods included from Options

#accept_options, #accepted_options, #options

Class Method Details

.to_boolean(value) ⇒ BigDecimal

Coerce given value to a Boolean

Examples:

with a 1

Virtus::Coercion::Fixnum.to_boolean(1)  # => true

with a 0

Virtus::Coercion::Fixnum.to_boolean(0)  # => false

Parameters:

  • value (Fixnum)

Returns:

  • (BigDecimal)


49
50
51
52
53
54
55
56
# File 'lib/virtus/coercion/integer.rb', line 49

def self.to_boolean(value)
  case value
  when 1 then true
  when 0 then false
  else
    value
  end
end

.to_integer(value) ⇒ Float

Passthrough the value

Examples:

Virtus::Coercion::Fixnum.to_integer(1)  # => 1

Parameters:

  • value (Fixnum)

Returns:



32
33
34
# File 'lib/virtus/coercion/integer.rb', line 32

def self.to_integer(value)
  value
end

.to_string(value) ⇒ String

Coerce given value to String

Examples:

Virtus::Coercion::Fixnum.to_string(1)  # => "1"

Parameters:

  • value (Fixnum)

Returns:



18
19
20
# File 'lib/virtus/coercion/integer.rb', line 18

def self.to_string(value)
  value.to_s
end