Module: RSchema::Coercers::Integer

Extended by:
Integer
Included in:
Integer
Defined in:
lib/rschema/coercers/integer.rb

Overview

Coerces values to Integers using Kernel#Integer

Instance Method Summary collapse

Instance Method Details

#build(_schema) ⇒ Object


10
11
12
# File 'lib/rschema/coercers/integer.rb', line 10

def build(_schema)
  self
end

#call(value) ⇒ Object


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

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

#will_affect?(value) ⇒ Boolean


23
24
25
# File 'lib/rschema/coercers/integer.rb', line 23

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