Class: OpenSCAP::Xccdf::Item

Inherits:
Object
  • Object
show all
Includes:
ItemCommon
Defined in:
lib/openscap/xccdf.rb,
lib/openscap/xccdf/item.rb

Overview

rubocop:disable Lint/EmptyClass

Direct Known Subclasses

Group, Rule, Value

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ItemCommon

#description, #id, #references, #title, #version

Constructor Details

#initialize(t) ⇒ Item

Returns a new instance of Item.



29
30
31
32
33
# File 'lib/openscap/xccdf/item.rb', line 29

def initialize t
  raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} abstract base class." if instance_of?(OpenSCAP::Xccdf::Item)

  @raw = t
end

Class Method Details

.build(t) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/openscap/xccdf/item.rb', line 14

def self.build t
  raise OpenSCAP::OpenSCAPError, "Cannot initialize #{self.class.name} with #{t}" \
    unless t.is_a?(FFI::Pointer)

  # This is Abstract base class that enables you to build its child
  case OpenSCAP.xccdf_item_get_type t
  when :group
    OpenSCAP::Xccdf::Group.new t
  when :rule
    OpenSCAP::Xccdf::Rule.new t
  else
    raise OpenSCAP::OpenSCAPError, "Unknown #{self.class.name} type: #{OpenSCAP.xccdf_item_get_type t}"
  end
end

Instance Method Details

#destroyObject



52
53
54
55
# File 'lib/openscap/xccdf/item.rb', line 52

def destroy
  OpenSCAP.xccdf_item_free @raw
  @raw = nil
end

#rationale(prefered_lang = nil, markup: false) ⇒ Object



35
36
37
# File 'lib/openscap/xccdf/item.rb', line 35

def rationale prefered_lang = nil, markup: false
  TextList.extract(OpenSCAP.xccdf_item_get_rationale(@raw), lang: prefered_lang, markup:)
end

#sub_itemsObject



50
# File 'lib/openscap/xccdf/item.rb', line 50

def sub_items = {}

#warningsObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/openscap/xccdf/item.rb', line 39

def warnings
  @warnings ||= [].tap do |warns|
    OpenSCAP._iterate over: OpenSCAP.xccdf_item_get_warnings(@raw), as: 'xccdf_warning' do |pointer|
      warns << {
        category: OpenSCAP.xccdf_warning_get_category(pointer),
        text: Text.new(OpenSCAP.xccdf_warning_get_text(pointer))
      }
    end
  end
end