Module: AbideDevUtils::XCCDF::Parser::Linker

Defined in:
lib/abide_dev_utils/xccdf/parser.rb

Overview

Links XCCDF objects by reference. Each link is resolved and then a bidirectional link is established between the two objects.

Class Method Summary collapse

Class Method Details



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/abide_dev_utils/xccdf/parser.rb', line 27

def self.link_profile_rules(benchmark)
  return unless benchmark.respond_to?(:profile)

  rules = benchmark.descendants.select { |d| d.label == 'rule' }
  benchmark.profile.each do |profile|
    profile.xccdf_select.each do |sel|
      rules.select { |rule| rule.id.value == sel.idref.value }.each do |rule|
        rule.add_link(profile)
        profile.add_link(rule)
      end
    end
  end
end


41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/abide_dev_utils/xccdf/parser.rb', line 41

def self.link_rule_values(benchmark)
  return unless benchmark.respond_to?(:value)

  rules = benchmark.descendants.select { |d| d.label == 'rule' }
  benchmark.value.each do |value|
    rule = rules.find { |r| r.title.to_s == value.title.to_s }
    next unless rule

    rule.add_link(value)
    value.add_link(rule)
  end
end


22
23
24
25
# File 'lib/abide_dev_utils/xccdf/parser.rb', line 22

def self.resolve_links(benchmark)
  link_profile_rules(benchmark)
  link_rule_values(benchmark)
end