Class: Opencdd::Validator::PatternRule
- Inherits:
-
Rule
- Object
- Rule
- Opencdd::Validator::PatternRule
show all
- Defined in:
- lib/opencdd/validator/pattern_rule.rb
Constant Summary
Constants inherited
from Rule
Rule::REFERENCE_VALUE_KINDS
Instance Method Summary
collapse
Methods inherited from Rule
#blank?, #code_column?, #reference_kind?, #skip_blank?, #value_passes?
Instance Method Details
#applies?(context) ⇒ Boolean
10
11
12
|
# File 'lib/opencdd/validator/pattern_rule.rb', line 10
def applies?(context)
!context.pattern.nil? && !context.pattern.to_s.strip.empty?
end
|
#call(value, context) ⇒ Object
14
15
16
17
18
19
|
# File 'lib/opencdd/validator/pattern_rule.rb', line 14
def call(value, context)
return true if value.nil? || value.to_s.strip.empty?
Regexp.new(context.pattern.to_s).match?(value.to_s)
rescue RegexpError
false
end
|
#id ⇒ Object
6
7
8
|
# File 'lib/opencdd/validator/pattern_rule.rb', line 6
def id
"R06"
end
|
#message(value, context) ⇒ Object
21
22
23
|
# File 'lib/opencdd/validator/pattern_rule.rb', line 21
def message(value, context)
"R06: #{value.inspect} does not match pattern #{context.pattern.inspect}"
end
|