Class: OpenSCAP::TextList

Inherits:
Object
  • Object
show all
Defined in:
lib/openscap/text.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(oscap_text_iterator) ⇒ TextList

Returns a new instance of TextList.



31
32
33
34
35
36
37
38
39
# File 'lib/openscap/text.rb', line 31

def initialize(oscap_text_iterator)
  @raw = oscap_text_iterator

  begin
    yield self
  ensure
    destroy
  end if block_given?
end

Class Method Details

.extract(pointer, lang:, markup:) ⇒ Object



56
57
58
59
60
61
62
63
64
# File 'lib/openscap/text.rb', line 56

def self.extract(pointer, lang:, markup:)
  new(pointer) do |list|
    if markup
      return list.markup(lang:)
    else
      return list.plaintext(lang)
    end
  end
end

Instance Method Details

#destroyObject



52
53
54
# File 'lib/openscap/text.rb', line 52

def destroy
  OpenSCAP.oscap_text_iterator_free @raw
end

#markup(lang:) ⇒ Object



45
46
47
48
49
50
# File 'lib/openscap/text.rb', line 45

def markup(lang:)
  text_pointer = OpenSCAP.oscap_textlist_get_preferred_text @raw, lang
  return nil if text_pointer.null?

  Text.new(text_pointer).text
end

#plaintext(lang = nil) ⇒ Object



41
42
43
# File 'lib/openscap/text.rb', line 41

def plaintext(lang = nil)
  OpenSCAP.oscap_textlist_get_preferred_plaintext @raw, lang
end