Class: Opencdd::Validator::ConditionRule

Inherits:
Rule
  • Object
show all
Defined in:
lib/opencdd/validator/condition_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

Returns:

  • (Boolean)


10
11
12
13
# File 'lib/opencdd/validator/condition_rule.rb', line 10

def applies?(context)
  context.column_iri == Opencdd::PropertyIds::MDC_P028 ||
    context.value_kind == :condition
end

#call(value, _context) ⇒ Object



15
16
17
18
19
20
# File 'lib/opencdd/validator/condition_rule.rb', line 15

def call(value, _context)
  return true if value.nil? || value.to_s.strip.empty?
  !Opencdd::Condition.parse(value.to_s).nil?
rescue ArgumentError
  false
end

#idObject



6
7
8
# File 'lib/opencdd/validator/condition_rule.rb', line 6

def id
  "R11"
end

#message(value, _context) ⇒ Object



22
23
24
# File 'lib/opencdd/validator/condition_rule.rb', line 22

def message(value, _context)
  "R11: condition expression #{value.inspect} is not well-formed"
end