Class: Opencdd::Validator::FormatRule
- Inherits:
-
Rule
- Object
- Rule
- Opencdd::Validator::FormatRule
show all
- Defined in:
- lib/opencdd/validator/format_rule.rb
Constant Summary
collapse
- TOKEN_PATTERN =
%r{
\A
(?<type>NR1|NR2|NR3|M|B|Date|DT|Bool)
(?:\s+(?<sign>S|U))?
(?:\.\.(?<width>\d+))?
(?:\.(?<decimals>\d+))?
\z
}x.freeze
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
19
20
21
|
# File 'lib/opencdd/validator/format_rule.rb', line 19
def applies?(context)
!context.value_format.nil? && !context.value_format.to_s.strip.empty?
end
|
#call(value, context) ⇒ Object
23
24
25
26
27
28
|
# File 'lib/opencdd/validator/format_rule.rb', line 23
def call(value, context)
return true if value.nil? || value.to_s.strip.empty?
match = TOKEN_PATTERN.match(context.value_format.to_s.strip)
return false unless match
type_check(value, match)
end
|
#id ⇒ Object
15
16
17
|
# File 'lib/opencdd/validator/format_rule.rb', line 15
def id
"R05"
end
|
#message(value, context) ⇒ Object
30
31
32
|
# File 'lib/opencdd/validator/format_rule.rb', line 30
def message(value, context)
"R05: #{value.inspect} does not match value format #{context.value_format}"
end
|