Class: HCast::Casters::TimeCaster
- Inherits:
-
Object
- Object
- HCast::Casters::TimeCaster
- Defined in:
- lib/hcast/casters/time_caster.rb
Class Method Summary collapse
Class Method Details
.cast(value, attr_name, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/hcast/casters/time_caster.rb', line 3 def self.cast(value, attr_name, = {}) if value.is_a?(Time) value elsif value.is_a?(String) begin Time.parse(value) rescue ArgumentError => e raise HCast::Errors::CastingError, "is invalid time" end else raise HCast::Errors::CastingError, "should be a time" end end |