Class: OpenscapParser::Value
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
Instance Method Details
#description ⇒ Object
10
11
12
|
# File 'lib/openscap_parser/value.rb', line 10
def description
@description ||= newline_to_whitespace(parsed_xml.at_css('description')&.text)
end
|
#generic_selector(type, selector = nil) ⇒ Object
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/openscap_parser/value.rb', line 22
def generic_selector(type, selector = nil)
cache = instance_variable_get("@#{type}")
unless cache
element_name = type.to_s.sub('_', '-')
cache = parsed_xml.xpath(element_name).each_with_object({}) do |element, elements|
elements[element.at_xpath('@selector')&.text.presence] = element&.text
end
instance_variable_set("@#{type}", cache)
end
return cache[selector] if selector
cache[nil] || cache.values.first
end
|
#id ⇒ Object
6
7
8
|
# File 'lib/openscap_parser/value.rb', line 6
def id
@id ||= parsed_xml['id']
end
|
#lower_bound(selector = nil) ⇒ Object
42
43
44
|
# File 'lib/openscap_parser/value.rb', line 42
def lower_bound(selector = nil)
generic_selector(:lower_bound, selector)
end
|
#title ⇒ Object
14
15
16
|
# File 'lib/openscap_parser/value.rb', line 14
def title
@title ||= parsed_xml.at_css('title')&.text
end
|
#to_h ⇒ Object
50
51
52
53
54
55
56
57
58
59
|
# File 'lib/openscap_parser/value.rb', line 50
def to_h
{
:id => id,
:title => title,
:description => description,
:type => type,
:lower_bound => lower_bound,
:upper_bound => upper_bound
}
end
|
#type ⇒ Object
18
19
20
|
# File 'lib/openscap_parser/value.rb', line 18
def type
@type ||= parsed_xml['type'] || 'string'
end
|
#upper_bound(selector = nil) ⇒ Object
38
39
40
|
# File 'lib/openscap_parser/value.rb', line 38
def upper_bound(selector = nil)
generic_selector(:upper_bound, selector)
end
|
#value(selector = nil) ⇒ Object
46
47
48
|
# File 'lib/openscap_parser/value.rb', line 46
def value(selector = nil)
generic_selector(:value, selector)
end
|