Sha256: e803bcbc4ab952012029f12ccbe20ed7f7941ceaf172b9426852b09ba0fb3d70

Contents?: true

Size: 598 Bytes

Versions: 7

Compression:

Stored size: 598 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

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
attributor-2.6.0 lib/attributor/types/float.rb
attributor-2.5.0 lib/attributor/types/float.rb
attributor-2.4.0 lib/attributor/types/float.rb
attributor-2.3.0 lib/attributor/types/float.rb
attributor-2.2.1 lib/attributor/types/float.rb
attributor-2.2.0 lib/attributor/types/float.rb
attributor-2.1.0 lib/attributor/types/float.rb