Sha256: 1561ec78708613281618b92d70354e0d528e57f3965f471c2e653b0c7e425d5e

Contents?: true

Size: 1.58 KB

Versions: 4

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true
module OpenscapParser
  class Group < XmlNode
    include OpenscapParser::Util

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

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

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

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

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

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

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

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

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

    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
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
openscap_parser-1.3.1 lib/openscap_parser/group.rb
openscap_parser-1.3.0 lib/openscap_parser/group.rb
openscap_parser-1.2.0 lib/openscap_parser/group.rb
openscap_parser-1.1.0 lib/openscap_parser/group.rb