Sha256: 8b1ca06ee9f6f3a0dbd18d3bae8d137d14353817dc916a9eef5d81b3a069778f

Contents?: true

Size: 771 Bytes

Versions: 26

Compression:

Stored size: 771 Bytes

Contents

module Foobara
  module BuiltinTypes
    module Datetime
      module Casters
        class String < Value::Caster
          def applicable?(value)
            value.is_a?(::String) && parse(value)
          end

          def applies_message
            "be a valid date string"
          end

          def cast(string)
            parse(string)
          end

          private

          def parse(string)
            # would be nice to do this some other way where we can verify against a regex independent of casting
            # to a Time especially since ArgumentError is way too generic. But might have to just stick with this
            ::Time.parse(string)
          rescue ArgumentError
            nil
          end
        end
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.25 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.24 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.23 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.22 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.21 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.20 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.19 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.18 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.17 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.16 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.15 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.14 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.13 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.12 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.11 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.10 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.9 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.8 projects/builtin_types/src/datetime/casters/string.rb
foobara-0.0.7 projects/builtin_types/src/datetime/casters/string.rb