Class: DailyAffirmation::Validators::FormatValidator

Inherits:
DailyAffirmation::Validator show all
Defined in:
lib/daily_affirmation/validators/format_validator.rb

Overview

This affirmation ensures an attribute matches the provided :regex option.

Instance Method Summary collapse

Methods inherited from DailyAffirmation::Validator

#affirm, #initialize

Constructor Details

This class inherits a constructor from DailyAffirmation::Validator

Instance Method Details

#error_messageObject



13
14
15
16
17
# File 'lib/daily_affirmation/validators/format_validator.rb', line 13

def error_message
  @error_message ||= i18n_error_message(
    :format, :default => "#{attribute} is invalid"
  )
end

#valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/daily_affirmation/validators/format_validator.rb', line 9

def valid?
  @valid ||= !!opts[:regex].match(value)
end