Class: OpenscapParser::Profile

Inherits:
XmlNode
  • Object
show all
Defined in:
lib/openscap_parser/profile.rb

Instance Attribute Summary

Attributes inherited from XmlNode

#namespaces

Instance Method Summary collapse

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

#descriptionObject



19
20
21
22
# File 'lib/openscap_parser/profile.rb', line 19

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

#extends_profile_idObject



9
10
11
# File 'lib/openscap_parser/profile.rb', line 9

def extends_profile_id
  @extends ||= @parsed_xml['extends']
end

#idObject



5
6
7
# File 'lib/openscap_parser/profile.rb', line 5

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

#refined_valuesObject



49
50
51
52
53
# File 'lib/openscap_parser/profile.rb', line 49

def refined_values
  @refined_values ||= @parsed_xml.xpath("refine-value").each_with_object({}) do |element, rv|
    rv[element.at_xpath('@idref').text] = element.at_xpath('@selector').text
  end
end

#selected_entity_idsObject



44
45
46
47
# File 'lib/openscap_parser/profile.rb', line 44

def selected_entity_ids
  @selected_entity_ids ||= @parsed_xml.xpath("select[@selected='true']/@idref") &&
    @parsed_xml.xpath("select[@selected='true']/@idref").map(&:text)
end

#selected_rule_idsObject



24
25
26
27
28
29
30
31
32
# File 'lib/openscap_parser/profile.rb', line 24

def selected_rule_ids
  # Look for selected rule ids where the idref contains '_rule_' that is not preceded by 'group'
  @selected_rule_ids ||= @parsed_xml.xpath("select[@selected='true']
                                                  [regex(@idref, '^((?!_group_).)*?(_rule_).*$')]
                                                  /@idref", RegexHandler) &&
                         @parsed_xml.xpath("select[@selected='true']
                                                  [regex(@idref, '^((?!_group_).)*?(_rule_).*$')]
                                                  /@idref", RegexHandler).map(&:text)
end

#titleObject Also known as: name



13
14
15
16
# File 'lib/openscap_parser/profile.rb', line 13

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

#to_hObject



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

def to_h
  {
    :id => id,
    :title => title,
    :description => description,
    :refined_values => refined_values
  }
end

#unselected_group_idsObject



34
35
36
37
38
39
40
41
42
# File 'lib/openscap_parser/profile.rb', line 34

def unselected_group_ids
  # Look for group ids that are not selected where the idref contains '_group_' that is not preceded by 'rule'
  @unselected_group_ids ||= @parsed_xml.xpath("select[@selected='false']
                                                     [regex(@idref, '^((?!_rule_).)*?(_group_).*$')]
                                                     /@idref", RegexHandler) &&
                            @parsed_xml.xpath("select[@selected='false']
                                                     [regex(@idref, '^((?!_rule_).)*?(_group_).*$')]
                                                     /@idref", RegexHandler).map(&:text)
end