Sha256: c547572c31258c2a9636c021d85223df72948553016f6716102e14c7140b4611

Contents?: true

Size: 429 Bytes

Versions: 2

Compression:

Stored size: 429 Bytes

Contents

module SimpleValidate
  class ValidatesFormatOf < ValidatesBase
    attr_accessor :regex

    def initialize(attribute, options)
      self.regex = options[:with]
      super(attribute, options[:message] ||
        'is incorrect format', options[:if] || proc { true })
    end

    def valid?(instance)
      raise ArgumentError if regex.nil? || !regex.is_a?(Regexp)
      !!(instance.send(attribute) =~ regex)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
simple_validate-1.2.2 lib/simple_validate/validates_format_of.rb
simple_validate-1.1.2 lib/simple_validate/validates_format_of.rb