class Sullivan::Validations::StringMatching
Public Class Methods
new(regex, error: nil)
click to toggle source
# File lib/sullivan/validations/string_matching.rb, line 4 def initialize(regex, error: nil) @regex = regex @custom_error = error end
Public Instance Methods
validate(value)
click to toggle source
# File lib/sullivan/validations/string_matching.rb, line 9 def validate(value) error unless value.respond_to?(:to_str) && value.to_str =~ @regex end
Private Instance Methods
error()
click to toggle source
# File lib/sullivan/validations/string_matching.rb, line 15 def error @custom_error || "must be a string matching #{@regex.inspect}" end