Class: Aequitas::Rule::Format::Regexp

Inherits:
Aequitas::Rule::Format show all
Defined in:
lib/aequitas/rule/format/regexp.rb

Constant Summary

Constants inherited from Aequitas::Rule::Format

EMAIL_ADDRESS, FORMATS, FORMAT_MESSAGES, URL

Instance Attribute Summary collapse

Attributes inherited from Aequitas::Rule::Format

#format

Attributes inherited from Aequitas::Rule

#attribute_name, #custom_message, #guard, #skip_condition

Attributes included from ValueObject

#equalizer

Instance Method Summary collapse

Methods inherited from Aequitas::Rule::Format

rules_for, #violation_type

Methods inherited from Aequitas::Rule

#attribute_value, #execute?, rules_for, #skip?, #validate, #violation_data, #violation_info, #violation_values

Methods included from ValueObject

#equalize_on

Constructor Details

#initialize(attribute_name, options = {}) ⇒ Regexp

Returns a new instance of Regexp.



14
15
16
17
18
# File 'lib/aequitas/rule/format/regexp.rb', line 14

def initialize(attribute_name, options = {})
  super

  @format_name = options.fetch(:format_name, nil)
end

Instance Attribute Details

#format_nameObject (readonly)

Returns the value of attribute format_name.



12
13
14
# File 'lib/aequitas/rule/format/regexp.rb', line 12

def format_name
  @format_name
end

Instance Method Details

#valid?(resource) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
26
27
28
# File 'lib/aequitas/rule/format/regexp.rb', line 20

def valid?(resource)
  value = attribute_value(resource)
  return true if skip?(value)

  value ? value.to_s =~ self.format : false
rescue ::Encoding::CompatibilityError
  # This is to work around a bug in jruby - see formats/email.rb
  false
end