7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/openscap_parser/subs.rb', line 7
def self.included(base)
base.class_eval do
def subs
return [] unless sub_nodes
@subs ||= sub_nodes.map do |xml|
Sub.new(parsed_xml: xml)
end
end
def sub_nodes(xpath = './/sub')
@sub_nodes ||= xpath_nodes(xpath)
end
def map_sub_nodes(children, set_values)
children.map do |child|
next child if child.name == 'text'
next replace_sub(Sub.new(parsed_xml: child), set_values) if child.name == 'sub'
child
end
end
private
def replace_sub(sub, set_values)
set_value = set_values.find { |set_value| set_value.id == sub.id }
return unless set_value
set_value.parsed_xml.children.first
end
end
end
|