Sha256: ec3a9fcde29e9c651dd8d2c3ed2d158c9046a6694c581f4d2c453043f9e5951d

Contents?: true

Size: 550 Bytes

Versions: 6

Compression:

Stored size: 550 Bytes

Contents

require 'parameters/types/object'

module Parameters
  module Types
    class Integer < Object

      #
      # Coerces a value into an Integer.
      #
      # @param [::String, #to_i] value
      #   The value to coerce.
      #
      # @return [::Integer]
      #   The coerced Integer.
      #
      def self.coerce(value)
        case value
        when ::String
          value.to_i(0)
        else
          if value.respond_to?(:to_i)
            value.to_i
          else
            0
          end
        end
      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
parameters-0.4.4 lib/parameters/types/integer.rb
parameters-0.4.3 lib/parameters/types/integer.rb
parameters-0.4.2 lib/parameters/types/integer.rb
parameters-0.4.0 lib/parameters/types/integer.rb
parameters-0.3.1 lib/parameters/types/integer.rb
parameters-0.3.0 lib/parameters/types/integer.rb