Class: Aequitas::Rule::Format::Regexp
- Inherits:
-
Aequitas::Rule::Format
- Object
- Aequitas::Rule
- Aequitas::Rule::Format
- Aequitas::Rule::Format::Regexp
- 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
-
#format_name ⇒ Object
readonly
Returns the value of attribute format_name.
Attributes inherited from Aequitas::Rule::Format
Attributes inherited from Aequitas::Rule
#attribute_name, #custom_message, #guard, #skip_condition
Attributes included from ValueObject
Instance Method Summary collapse
-
#initialize(attribute_name, options = {}) ⇒ Regexp
constructor
A new instance of Regexp.
- #valid?(resource) ⇒ Boolean
Methods inherited from Aequitas::Rule::Format
Methods inherited from Aequitas::Rule
#attribute_value, #execute?, rules_for, #skip?, #validate, #violation_data, #violation_info, #violation_values
Methods included from ValueObject
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, = {}) super @format_name = .fetch(:format_name, nil) end |
Instance Attribute Details
#format_name ⇒ Object (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
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 |