Sha256: d6fd7248ef4fcbb872d58fe7abf180569a7e878bef0da1066b56b94cc905c256

Contents?: true

Size: 641 Bytes

Versions: 5

Compression:

Stored size: 641 Bytes

Contents

# Float objects represent inexact real numbers using the native architecture's double-precision floating point representation.
# See: http://ruby-doc.org/core-2.1.0/Float.html

module Attributor
  class Float
    include Type

    def self.native_type
      ::Float
    end

    def self.example(_context = nil, options: {})
      min = options[:min].to_f || 0.0
      max = options[:max].to_f || Math.PI

      rand * (max - min) + min
    end

    def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
      Float(value)
    rescue TypeError
      super
    end

    def self.family
      'numeric'
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
attributor-5.4 lib/attributor/types/float.rb
attributor-5.3 lib/attributor/types/float.rb
attributor-5.2.1 lib/attributor/types/float.rb
attributor-5.2.0 lib/attributor/types/float.rb
attributor-5.1.0 lib/attributor/types/float.rb