Module: RSchema::Coercers::Date

Extended by:
Date
Included in:
Date
Defined in:
lib/rschema/coercers/date.rb

Instance Method Summary collapse

Instance Method Details

#build(schema) ⇒ Object


7
8
9
# File 'lib/rschema/coercers/date.rb', line 7

def build(schema)
  self
end

#call(value) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rschema/coercers/date.rb', line 11

def call(value)
  case value
  when ::Date
    Result.success(value)
  when ::String
    date = ::Date.parse(value) rescue nil
    date ? Result.success(date) : Result.failure
  else
    Result.failure
  end
end