Sha256: bf3635b32d96ed3529d18232a3a8ca7e79a3f2d527e652bf0c785c688b2b392e

Contents?: true

Size: 797 Bytes

Versions: 3

Compression:

Stored size: 797 Bytes

Contents

module Rasti
  class Form
    module Types
      class String
        class << self

          include Castable

          def [](format)
            Class.new(self) do
              @format = format.is_a?(::String) ? ::Regexp.new(format) : format
            end
          end

          def to_s
            name || "#{superclass.name}[#{format.inspect}]"
          end
          alias_method :inspect, :to_s

          private

          attr_reader :format

          def valid?(value)
            !value.nil? && value.respond_to?(:to_s) && valid_format?(value)
          end

          def valid_format?(value)
            format.nil? || !value.to_s.match(format).nil?
          end

          def transform(value)
            value.to_s
          end

        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rasti-form-3.1.2 lib/rasti/form/types/string.rb
rasti-form-3.1.1 lib/rasti/form/types/string.rb
rasti-form-3.1.0 lib/rasti/form/types/string.rb