Class: OpenSCAP::Xccdf::Item

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

Direct Known Subclasses

Group, Rule, Value

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(t) ⇒ Item

Returns a new instance of Item.



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

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

Class Method Details

.build(t) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/openscap/xccdf/item.rb', line 21

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

#description(prefered_lang = nil) ⇒ Object



53
54
55
56
57
58
# File 'lib/openscap/xccdf/item.rb', line 53

def description(prefered_lang = nil)
  textlist = OpenSCAP::TextList.new(OpenSCAP.xccdf_item_get_description(@raw))
  description = textlist.plaintext(prefered_lang)
  textlist.destroy
  description
end

#destroyObject



82
83
84
85
# File 'lib/openscap/xccdf/item.rb', line 82

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

#idObject



42
43
44
# File 'lib/openscap/xccdf/item.rb', line 42

def id
  OpenSCAP.xccdf_item_get_id @raw
end

#rationale(prefered_lang = nil) ⇒ Object



60
61
62
63
64
65
# File 'lib/openscap/xccdf/item.rb', line 60

def rationale(prefered_lang = nil)
  textlist = OpenSCAP::TextList.new(OpenSCAP.xccdf_item_get_rationale(@raw))
  rationale = textlist.plaintext(prefered_lang)
  textlist.destroy
  rationale
end

#referencesObject



67
68
69
70
71
72
73
74
75
76
# File 'lib/openscap/xccdf/item.rb', line 67

def references
  refs = []
  refs_it = OpenSCAP.xccdf_item_get_references(@raw)
  while OpenSCAP.oscap_reference_iterator_has_more refs_it
    ref = OpenSCAP::Xccdf::Reference.new(OpenSCAP.oscap_reference_iterator_next(refs_it))
    refs << ref
  end
  OpenSCAP.oscap_reference_iterator_free refs_it
  refs
end

#sub_itemsObject



78
79
80
# File 'lib/openscap/xccdf/item.rb', line 78

def sub_items
  @sub_items ||= sub_items_init
end

#title(prefered_lang = nil) ⇒ Object



46
47
48
49
50
51
# File 'lib/openscap/xccdf/item.rb', line 46

def title(prefered_lang = nil)
  textlist = OpenSCAP::TextList.new(OpenSCAP.xccdf_item_get_title(@raw))
  title = textlist.plaintext(prefered_lang)
  textlist.destroy
  title
end