Class: Rbdantic::Validators::Types::Time

Inherits:
Base
  • Object
show all
Defined in:
lib/rbdantic/validators/types/time.rb

Instance Attribute Summary

Attributes inherited from Base

#constraints

Instance Method Summary collapse

Methods inherited from Base

#initialize, #validate, #validate_constraints

Constructor Details

This class inherits a constructor from Rbdantic::Validators::Types::Base

Instance Method Details

#coerce(value) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rbdantic/validators/types/time.rb', line 18

def coerce(value)
  case value
  when ::Time
    value
  when ::DateTime
    value.to_time
  when ::Date
    value.to_time
  when ::String
    ::Time.iso8601(value)
  when ::Integer, ::Float
    ::Time.at(value)
  end
rescue ArgumentError
  nil
end

#expected_type_nameObject



14
15
16
# File 'lib/rbdantic/validators/types/time.rb', line 14

def expected_type_name
  "Time"
end

#matches_type?(value) ⇒ Boolean

Returns:



10
11
12
# File 'lib/rbdantic/validators/types/time.rb', line 10

def matches_type?(value)
  value.is_a?(::Time)
end