module Yema class Rule class Format < self attr_reader :format def initialize(attribute_name, options={}) super extract_options(options) end def self.required_options [:format] end def matches?(value) !!(format =~ value) end private def extract_options(options) @format = options.fetch(:format) raise InvalidOptionError, "Format option only accept Regexp" unless format.kind_of?(Regexp) end end end end