Sha256: 0fa0cc9d1adee63380f7928d18f6df8705b7ecd7523cab7e22a7825e61f990a8

Contents?: true

Size: 399 Bytes

Versions: 6

Compression:

Stored size: 399 Bytes

Contents

require 'jschematic/element'

module Jschematic
  module Attributes
    class Pattern
      include Jschematic::Element

      def initialize(pattern)
        @pattern = Regexp.new(pattern)
      end

      def accepts?(instance)
        return true unless String === instance
        instance.match(@pattern) || fail_validation!("string matching #{@pattern}", instance)
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
jschematic-0.1.0 lib/jschematic/attributes/pattern.rb
jschematic-0.0.9 lib/jschematic/attributes/pattern.rb
jschematic-0.0.6 lib/jschematic/attributes/pattern.rb
jschematic-0.0.5 lib/jschematic/attributes/pattern.rb
jschematic-0.0.2 lib/jschematic/attributes/pattern.rb
jschematic-0.0.1 lib/jschematic/attributes/pattern.rb