Sha256: e9fc780a9c23404f4692b4acd47824753f676385d6554cdc57fbb328fb1c62ce

Contents?: true

Size: 1.19 KB

Versions: 16

Compression:

Stored size: 1.19 KB

Contents

module Virtus
  class Coercion

    # Coerce Fixnum values
    class Integer < Numeric
      primitive ::Integer

      # Coerce given value to String
      #
      # @example
      #   Virtus::Coercion::Fixnum.to_string(1)  # => "1"
      #
      # @param [Fixnum] value
      #
      # @return [String]
      #
      # @api public
      def self.to_string(value)
        value.to_s
      end

      # Passthrough the value
      #
      # @example
      #   Virtus::Coercion::Fixnum.to_integer(1)  # => 1
      #
      # @param [Fixnum] value
      #
      # @return [Float]
      #
      # @api public
      def self.to_integer(value)
        value
      end

      # Coerce given value to a Boolean
      #
      # @example with a 1
      #   Virtus::Coercion::Fixnum.to_boolean(1)  # => true
      #
      # @example with a 0
      #   Virtus::Coercion::Fixnum.to_boolean(0)  # => false
      #
      # @param [Fixnum] value
      #
      # @return [BigDecimal]
      #
      # @api public
      def self.to_boolean(value)
        case value
        when 1 then true
        when 0 then false
        else
          value
        end
      end

    end # class Fixnum
  end # class Coercion
end # module Virtus

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
virtus-0.5.3 lib/virtus/coercion/integer.rb
fragrant-0.0.5 vendor/bundle/ruby/1.9.1/gems/virtus-0.5.2/lib/virtus/coercion/integer.rb
virtus-0.5.2 lib/virtus/coercion/integer.rb
virtus-0.5.1 lib/virtus/coercion/integer.rb
virtus-0.5.0 lib/virtus/coercion/integer.rb
virtus-0.4.2 lib/virtus/coercion/integer.rb
virtus-0.4.1 lib/virtus/coercion/integer.rb
virtus-0.4.0 lib/virtus/coercion/integer.rb
virtus-0.3.0 lib/virtus/coercion/integer.rb
virtus-0.2.0 lib/virtus/coercion/integer.rb
virtus-0.1.0 lib/virtus/coercion/integer.rb
virtus-0.0.10 lib/virtus/coercion/integer.rb
virtus-0.0.9 lib/virtus/coercion/integer.rb
virtus-0.0.8 lib/virtus/coercion/integer.rb
virtus-0.0.7 lib/virtus/coercion/integer.rb
virtus-0.0.6 lib/virtus/coercion/integer.rb