Sha256: f6bc645b87332fa6fbda9ce405961af674797b694552f4a5eafe726b523fb974

Contents?: true

Size: 278 Bytes

Versions: 9

Compression:

Stored size: 278 Bytes

Contents

module SafeYAML
  class Transform
    class ToDate
      MATCHER = /\A\d{4}\-\d{2}\-\d{2}\Z/.freeze

      def transform?(value)
        return false unless MATCHER.match(value)
        date = Date.parse(value) rescue nil
        return !!date, date
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
safe_yaml-0.8.3 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.8.2 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.8.1 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.8.0 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.7.1 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.7.0 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.6.3 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.6.2 lib/safe_yaml/transform/to_date.rb
safe_yaml-0.6.1 lib/safe_yaml/transform/to_date.rb