Sha256: aa32f53ab84fcb327c6199f7d2c47cd632bd464efe492a61d8812ad649881b6b

Contents?: true

Size: 646 Bytes

Versions: 10

Compression:

Stored size: 646 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
      return ::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

10 entries across 10 versions & 1 rubygems

Version Path
attributor-5.0.2 lib/attributor/types/float.rb
attributor-5.0.1 lib/attributor/types/float.rb
attributor-5.0 lib/attributor/types/float.rb
attributor-4.2.0 lib/attributor/types/float.rb
attributor-4.1.0 lib/attributor/types/float.rb
attributor-4.0.1 lib/attributor/types/float.rb
attributor-4.0.0 lib/attributor/types/float.rb
attributor-3.0.1 lib/attributor/types/float.rb
attributor-3.0 lib/attributor/types/float.rb
attributor-2.6.1 lib/attributor/types/float.rb