Class: Dcc::Validate::Schematron::Rules::ReleaseFormatCheck

Inherits:
Base show all
Defined in:
lib/dcc/validate/schematron/rules/release_format_check.rb

Overview

Validates dcc:release format: ^[a-zA-Z]{1}(\s)?([0-9]{1,3}\.){0,3}([0-9]{1,3})$

Constant Summary collapse

PATTERN =
/\A[a-zA-Z]{1} ?([0-9]{1,3}\.){0,3}[0-9]{1,3}\z/

Instance Method Summary collapse

Methods inherited from Dcc::Validate::Schematron::Rule

#code, #severity

Instance Method Details

#check_on(dcc) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/dcc/validate/schematron/rules/release_format_check.rb', line 12

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

  software_list = safe_attr(dcc.administrative_data, :dcc_software)
  return issues if software_list.nil?

  Array(safe_attr(software_list, :software)).each do |sw|
    release = Dcc::TypeGuards.has_attribute?(sw, :release) ? sw.release : nil
    next if release.nil? || release.empty?
    next if release.match?(PATTERN)

    issues << issue(
      severity: :error,
      message: "dcc:release '#{release}' does not match the expected format",
    )
  end

  issues
end