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