Sha256: 5d02b56b66d6259512febaabe123d7288178b54e20494920a91419c4b0d65f13
Contents?: true
Size: 737 Bytes
Versions: 10
Compression:
Stored size: 737 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, attributes) value.blank? || value =~ pattern end def message(value, attributes) "#{value.inspect} does not match #{pattern.inspect}" end end end end
Version data entries
10 entries across 10 versions & 1 rubygems