Sha256: 79eaa3a1154f0589f88918563b927e7026695dc06a9103482302979c2424794e

Contents?: true

Size: 703 Bytes

Versions: 14

Compression:

Stored size: 703 Bytes

Contents

module Rasti
  class Form
    module Types
      class Time

        include Castable

        attr_reader :format

        def self.[](format)
          new format
        end

        def to_s
          "#{self.class}['#{format}']"
        end
        alias_method :inspect, :to_s

        private

        def initialize(format)
          @format = format
        end

        def valid?(value)
          value.is_a?(::String) || value.respond_to?(:to_time)
        end

        def transform(value)
          value.is_a?(::String) ? string_to_time(value) : value.to_time
        end

        def string_to_time(value)
          ::Time.strptime(value, format)
        end

      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/time.rb
rasti-form-3.1.1 lib/rasti/form/types/time.rb
rasti-form-3.1.0 lib/rasti/form/types/time.rb
rasti-form-3.0.0 lib/rasti/form/types/time.rb
rasti-form-2.2.0 lib/rasti/form/types/time.rb
rasti-form-2.1.0 lib/rasti/form/types/time.rb
rasti-form-2.0.0 lib/rasti/form/types/time.rb
rasti-form-1.1.1 lib/rasti/form/types/time.rb
rasti-form-1.1.0 lib/rasti/form/types/time.rb
rasti-form-1.0.3 lib/rasti/form/types/time.rb
rasti-form-1.0.2 lib/rasti/form/types/time.rb
rasti-form-1.0.1 lib/rasti/form/types/time.rb
rasti-form-1.0.0 lib/rasti/form/types/time.rb
rasti-form-0.1.0 lib/rasti/form/types/time.rb