Sha256: 850440ec5ed769784472e3be4473c945d235ae126d9ffa49ec591b166b50831c

Contents?: true

Size: 699 Bytes

Versions: 13

Compression:

Stored size: 699 Bytes

Contents

require 'hermod/validators/base'

module Hermod
  module Validators
    # Checks the value matches the given regular expression
    class RegularExpression < Base
      attr_reader :pattern

      # Sets up the pattern the value is expected to match
      def initialize(pattern)
        @pattern = pattern
      end

      private

      # Public: Checks the value matches the pattern. Blank values are ignored
      # because those are checked by the ValuePresence validator if necessary.
      #
      # Returns a boolean
      def test
        value.blank? || value =~ pattern
      end

      def message
        "#{value.inspect} does not match #{pattern.inspect}"
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hermod-2.5.0 lib/hermod/validators/regular_expression.rb
hermod-2.4.1 lib/hermod/validators/regular_expression.rb
hermod-2.4.0 lib/hermod/validators/regular_expression.rb
hermod-2.2.0 lib/hermod/validators/regular_expression.rb
hermod-2.1.0 lib/hermod/validators/regular_expression.rb
hermod-1.2.9 lib/hermod/validators/regular_expression.rb
hermod-1.2.8 lib/hermod/validators/regular_expression.rb
hermod-1.2.7 lib/hermod/validators/regular_expression.rb
hermod-1.2.6 lib/hermod/validators/regular_expression.rb
hermod-1.2.5 lib/hermod/validators/regular_expression.rb
hermod-1.2.4 lib/hermod/validators/regular_expression.rb
hermod-1.2.3 lib/hermod/validators/regular_expression.rb
hermod-1.2.2 lib/hermod/validators/regular_expression.rb