Class: Dcc::Validate::BusinessRules::MainSignerSingle

Inherits:
Rule
  • Object
show all
Defined in:
lib/dcc/validate/business_rules.rb

Overview

Require exactly one respPerson with mainSigner = true.

Instance Method Summary collapse

Methods inherited from Rule

#code, #severity

Instance Method Details

#check_on(dcc) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dcc/validate/business_rules.rb', line 70

def check_on(dcc)
  return [] unless Dcc::TypeGuards.has_attribute?(dcc, :administrative_data)

  admin = dcc.administrative_data
  return [] unless admin && Dcc::TypeGuards.has_attribute?(admin, :resp_persons) && admin.resp_persons

  resp_persons = Array(admin.resp_persons.resp_person)
  main_signers = resp_persons.select { |p| Dcc::TypeGuards.has_attribute?(p, :main_signer) && p.main_signer }
  return [] if main_signers.size == 1

  [
    issue(
      severity: :error,
      message: "Expected exactly one mainSigner respPerson, found #{main_signers.size}",
    ),
  ]
end