class Attributor::Float

Public Class Methods

example(_context = nil, options: {}) click to toggle source
# File lib/attributor/types/float.rb, line 13
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
json_schema_type() click to toggle source
# File lib/attributor/types/float.rb, line 27
def self.json_schema_type
  :number
end
load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options) click to toggle source
Calls superclass method
# File lib/attributor/types/float.rb, line 20
def self.load(value, context = Attributor::DEFAULT_ROOT_CONTEXT, **options)
  return Float(value + '0') if value.is_a?(::String) && value.end_with?('.')
  Float(value)
rescue TypeError
  super
end
native_type() click to toggle source
# File lib/attributor/types/float.rb, line 9
def self.native_type
  ::Float
end