Sha256: 155e09912af17634a418e96798b90b7f6a53c2da42a19fa515f7d501483c9e26
Contents?: true
Size: 709 Bytes
Versions: 2
Compression:
Stored size: 709 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.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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
rasti-types-2.0.1 | lib/rasti/types/string.rb |
rasti-types-2.0.0 | lib/rasti/types/string.rb |