Class: OpenscapParser::Group

Inherits:
XmlNode
  • Object
show all
Includes:
Util
Defined in:
lib/openscap_parser/group.rb

Instance Attribute Summary

Attributes inherited from XmlNode

#namespaces

Instance Method Summary collapse

Methods included from Util

#newline_to_whitespace

Methods inherited from XmlNode

#initialize, #parsed_xml, #text, #xpath_node, #xpath_nodes

Constructor Details

This class inherits a constructor from OpenscapParser::XmlNode

Instance Method Details

#conflictsObject



36
37
38
39
40
41
# File 'lib/openscap_parser/group.rb', line 36

def conflicts
  @conflicts ||= parsed_xml.xpath('./conflicts') &&
    parsed_xml.xpath('./conflicts/@idref').flat_map do |c|
      c.to_s&.split
    end
end

#descriptionObject



15
16
17
18
19
20
# File 'lib/openscap_parser/group.rb', line 15

def description
  @description ||= newline_to_whitespace(
    parsed_xml.at_css('description') &&
      parsed_xml.at_css('description').text || ''
  )
end

#idObject



6
7
8
# File 'lib/openscap_parser/group.rb', line 6

def id
  @id ||= parsed_xml['id']
end

#parent_idObject



47
48
49
# File 'lib/openscap_parser/group.rb', line 47

def parent_id
  @parent_id = parsed_xml.xpath('../@id').to_s
end

#parent_idsObject



51
52
53
# File 'lib/openscap_parser/group.rb', line 51

def parent_ids
  @parent_ids = parsed_xml.xpath('ancestor::Group/@id').map(&:value)
end

#parent_typeObject



55
56
57
58
59
60
61
# File 'lib/openscap_parser/group.rb', line 55

def parent_type
  if parsed_xml.xpath("name(..)='Group'")
    @parent_type = 'Group'
  else
    @parent_type = 'Benchmark'
  end
end

#rationaleObject



22
23
24
25
26
27
# File 'lib/openscap_parser/group.rb', line 22

def rationale
  @rationale ||= newline_to_whitespace(
    parsed_xml.at_css('rationale') &&
      parsed_xml.at_css('rationale').text || ''
  )
end

#requiresObject



29
30
31
32
33
34
# File 'lib/openscap_parser/group.rb', line 29

def requires
  @requires ||= parsed_xml.xpath('./requires') &&
    parsed_xml.xpath('./requires/@idref').flat_map do |r|
      r.to_s&.split
    end
end

#selectedObject



43
44
45
# File 'lib/openscap_parser/group.rb', line 43

def selected
  @selected ||= parsed_xml['selected']
end

#titleObject



10
11
12
13
# File 'lib/openscap_parser/group.rb', line 10

def title
  @title ||= parsed_xml.at_css('title') &&
    parsed_xml.at_css('title').text
end

#to_hObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/openscap_parser/group.rb', line 63

def to_h
  {
    :id => id,
    :title => title,
    :description => description,
    :requires => requires,
    :conflicts => conflicts,
    :rationale => rationale,
    :selected => selected,
    :parent_id => parent_id,
    :parent_type => parent_type
  }
end