|
| 1 | +# frozen_string_literal: true |
| 2 | +module OpenscapParser |
| 3 | + class Group < XmlNode |
| 4 | + include OpenscapParser::Util |
| 5 | + |
| 6 | + def id |
| 7 | + @id ||= parsed_xml['id'] |
| 8 | + end |
| 9 | + |
| 10 | + def title |
| 11 | + @title ||= parsed_xml.at_css('title') && |
| 12 | + parsed_xml.at_css('title').text |
| 13 | + end |
| 14 | + |
| 15 | + def description |
| 16 | + @description ||= newline_to_whitespace( |
| 17 | + parsed_xml.at_css('description') && |
| 18 | + parsed_xml.at_css('description').text || '' |
| 19 | + ) |
| 20 | + end |
| 21 | + |
| 22 | + def rationale |
| 23 | + @rationale ||= newline_to_whitespace( |
| 24 | + parsed_xml.at_css('rationale') && |
| 25 | + parsed_xml.at_css('rationale').text || '' |
| 26 | + ) |
| 27 | + end |
| 28 | + |
| 29 | + def requires |
| 30 | + @requires ||= parsed_xml.xpath('./requires') && |
| 31 | + parsed_xml.xpath('./requires/@idref').flat_map do |r| |
| 32 | + r.to_s&.split |
| 33 | + end |
| 34 | + end |
| 35 | + |
| 36 | + def conflicts |
| 37 | + @conflicts ||= parsed_xml.xpath('./conflicts') && |
| 38 | + parsed_xml.xpath('./conflicts/@idref').flat_map do |c| |
| 39 | + c.to_s&.split |
| 40 | + end |
| 41 | + end |
| 42 | + |
| 43 | + def selected |
| 44 | + @selected ||= parsed_xml['selected'] |
| 45 | + end |
| 46 | + |
| 47 | + def parent_id |
| 48 | + @parent_id = parsed_xml.xpath('../@id').to_s |
| 49 | + end |
| 50 | + |
| 51 | + def parent_type |
| 52 | + if parsed_xml.xpath("name(..)='Group'") |
| 53 | + @parent_type = 'Group' |
| 54 | + else |
| 55 | + @parent_type = 'Benchmark' |
| 56 | + end |
| 57 | + end |
| 58 | + |
| 59 | + def to_h |
| 60 | + { |
| 61 | + :id => id, |
| 62 | + :title => title, |
| 63 | + :description => description, |
| 64 | + :requires => requires, |
| 65 | + :conflicts => conflicts, |
| 66 | + :rationale => rationale, |
| 67 | + :selected => selected, |
| 68 | + :parent_id => parent_id, |
| 69 | + :parent_type => parent_type |
| 70 | + } |
| 71 | + end |
| 72 | + end |
| 73 | +end |
0 commit comments