Module: RSchema::Coercers::Float

Extended by:
Float
Included in:
Float
Defined in:
lib/rschema/coercers/float.rb

Overview

Coerces values into Float objects using Kernel#Float

Instance Method Summary collapse

Instance Method Details

#build(_schema) ⇒ Object


11
12
13
# File 'lib/rschema/coercers/float.rb', line 11

def build(_schema)
  self
end

#call(value) ⇒ Object


15
16
17
18
19
20
21
22
# File 'lib/rschema/coercers/float.rb', line 15

def call(value)
  flt = begin
          Float(value)
        rescue
          nil
        end
  flt ? Result.success(flt) : Result.failure
end

#will_affect?(value) ⇒ Boolean


24
25
26
# File 'lib/rschema/coercers/float.rb', line 24

def will_affect?(value)
  !value.is_a?(Float)
end