Class: Virtus::Coercion::Integer
- Inherits:
-
Numeric
- Object
- Virtus::Coercion
- Object
- Numeric
- Virtus::Coercion::Integer
- 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
Class Method Summary collapse
-
.to_boolean(value) ⇒ BigDecimal
Coerce given value to a Boolean.
-
.to_datetime(value) ⇒ DateTime
Coerce given value to a DateTime.
-
.to_integer(value) ⇒ Float
Passthrough the value.
-
.to_string(value) ⇒ String
Coerce given value to String.
Methods inherited from Numeric
Methods inherited from Object
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_boolean(value) ⇒ BigDecimal
Coerce given value to a Boolean
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_datetime(value) ⇒ DateTime
Coerce given value to a DateTime
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/virtus/coercion/integer.rb', line 68 def self.to_datetime(value) # FIXME: Remove after Rubinius 2.0 is released if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx' datetime_format = '%Q' value = "#{value * 10**3}" else datetime_format = '%s' value = "#{value}" end ::DateTime.strptime(value, datetime_format) end |
.to_integer(value) ⇒ Float
Passthrough the value
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
18 19 20 |
# File 'lib/virtus/coercion/integer.rb', line 18 def self.to_string(value) value.to_s end |