Class: SafeYAML::Transform::ToTime
- Inherits:
-
Object
- Object
- SafeYAML::Transform::ToTime
- Defined in:
- lib/safe_yaml/transform/to_time.rb
Constant Summary collapse
- MATCHER =
There isn’t a missing ‘$’ there; YAML itself seems to ignore everything at the end of a string that otherwise resembles a time.
/\A\d{4}\-\d{2}\-\d{2} \d{2}:\d{2}:\d{2}(?:\.\d{1,5})?/.freeze
Instance Method Summary collapse
Instance Method Details
#transform?(value) ⇒ Boolean
8 9 10 11 12 13 14 15 |
# File 'lib/safe_yaml/transform/to_time.rb', line 8 def transform?(value) return false unless MATCHER.match(value) datetime = DateTime.parse(value) rescue nil if datetime.respond_to?(:to_time) return true, datetime.to_time end false end |