Sha256: 4a599c6e62a9c8e7699a2b2e3498d2432405c9bcf80b383bf1d1ea4b4cb872d5
Contents?: true
Size: 724 Bytes
Versions: 4
Compression:
Stored size: 724 Bytes
Contents
module Rasti 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
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
rasti-types-1.1.2 | lib/rasti/types/string.rb |
rasti-types-1.1.1 | lib/rasti/types/string.rb |
rasti-types-1.1.0 | lib/rasti/types/string.rb |
rasti-types-1.0.0 | lib/rasti/types/string.rb |