Class: AbideDevUtils::XCCDF::Parser::Objects::ElementBase
Overview
Base class for XCCDF element objects
Direct Known Subclasses
AttributeValue, Benchmark, Check, CheckContentRef, CheckExport, ComplexCheck, ControlURI, Description, ElementWithId, ElementWithIdref, Fixtext, Ident, LongText, Metadata, MetadataCisControls, MetadataCisControlsFramework, MetadataCisControlsFrameworkSafeguard, Platform, Rationale, ShortText, Status, System, Title, Version
Constant Summary
collapse
- UNICODE_SYMBOLS =
{
vertical: "\u2502",
horizontal: "\u2500",
tee: "\u251C",
corner: "\u2514"
}.freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
-
.xmlns ⇒ Object
For subclasses that are associated with a specific XCCDF element that has valid namespace prefix, this method returns that namespaces.
-
.xpath ⇒ Object
For subclasses that are associated with a specific XCCDF element, this method returns the element’s xpath name.
Instance Method Summary
collapse
find_element
#check_diffable!, #correlate_added_removed, #diff, #diff_ambiguous, #diff_array_obj, #diff_benchmark, #diff_change_result, #diff_check, #diff_complex_check, #diff_group, #diff_plain_obj, #diff_profile, #diff_rule, #diff_str_obj, #diff_value, #diff_xccdf_select, #process_details_hash!, #result_from_details_hash
Constructor Details
#initialize(*_args, parent_node: nil, **_kwargs) ⇒ ElementBase
Returns a new instance of ElementBase.
[View source]
28
29
30
31
32
33
34
35
36
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 28
def initialize(*_args, parent_node: nil, **_kwargs)
@parent = parent_node
@children = []
@links = []
@link_labels = []
@child_labels = []
@label_method_values = {}
@similarity_methods = []
end
|
Instance Attribute Details
#child_labels ⇒ Object
Returns the value of attribute child_labels.
26
27
28
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 26
def child_labels
@child_labels
end
|
#children ⇒ Object
Returns the value of attribute children.
26
27
28
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 26
def children
@children
end
|
#link_labels ⇒ Object
Returns the value of attribute link_labels.
26
27
28
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 26
def link_labels
@link_labels
end
|
#links ⇒ Object
Returns the value of attribute links.
26
27
28
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 26
def links
@links
end
|
#parent ⇒ Object
Returns the value of attribute parent.
26
27
28
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 26
def parent
@parent
end
|
Class Method Details
.xmlns ⇒ Object
For subclasses that are associated with a specific XCCDF element that has valid namespace prefix, this method returns that namespaces. May be overridden by subclasses if they have a different valid namespace prefix.
[View source]
51
52
53
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 51
def self.xmlns
'xccdf'
end
|
.xpath ⇒ Object
For subclasses that are associated with a specific XCCDF element, this method returns the element’s xpath name. Must be overridden by subclasses that implement this method.
[View source]
42
43
44
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 42
def self.xpath
nil
end
|
Instance Method Details
#<=>(other) ⇒ Object
[View source]
72
73
74
75
76
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 72
def <=>(other)
return nil unless other.is_a?(self.class)
label <=> other.label
end
|
#add_link(object) ⇒ Object
[View source]
102
103
104
105
106
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 102
def add_link(object)
define_child_method(object.label, linked: true)
@links << object
@link_labels << object.label unless @link_labels.include?(object.label)
end
|
#add_links(objects) ⇒ Object
[View source]
108
109
110
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 108
def add_links(objects)
objects.each { |object| add_link(object) }
end
|
#all_values ⇒ Object
[View source]
63
64
65
66
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 63
def all_values
@child_labels.map { |label| send(label.to_sym) }
@label_method_values
end
|
#ancestors ⇒ Object
[View source]
132
133
134
135
136
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 132
def ancestors
return [] if root?
[parent] + parent.ancestors
end
|
#depth ⇒ Object
[View source]
144
145
146
147
148
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 144
def depth
return 0 if root?
1 + parent.depth
end
|
#descendants ⇒ Object
[View source]
138
139
140
141
142
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 138
def descendants
return [] if leaf?
children + children.map(&:descendants).flatten
end
|
#find_similarity(other) ⇒ Object
[View source]
92
93
94
95
96
97
98
99
100
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 92
def find_similarity(other)
return [] unless other.is_a?(self.class)
@similarity_methods.each_with_object([]) do |method, ary|
val = send(method)
other_val = other.send(method)
ary << [method, val, other_val, val.eql?(other_val)]
end
end
|
#inspect ⇒ Object
[View source]
68
69
70
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 68
def inspect
"<#{self.class}:#{object_id}:\"#{self}\">"
end
|
#label ⇒ Object
[View source]
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 78
def label
return @label if defined?(@label)
@label = case self.class.name
when 'AbideDevUtils::XCCDF::Parser::Objects::AttributeValue'
@attribute.to_s
when /AbideDevUtils::XCCDF::Parser::Objects::(ShortText|LongText)/
'text'
else
self.class.name.split('::').last.split(/(?=[A-Z])/).join('_').downcase
end
@label
end
|
#leaf? ⇒ Boolean
[View source]
122
123
124
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 122
def leaf?
children.empty?
end
|
#print_tree ⇒ Object
[View source]
150
151
152
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 150
def print_tree
puts tree_string_parts.join("\n")
end
|
#root ⇒ Object
[View source]
116
117
118
119
120
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 116
def root
return self if root?
parent.root
end
|
#root? ⇒ Boolean
[View source]
112
113
114
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 112
def root?
parent.nil?
end
|
#siblings ⇒ Object
[View source]
126
127
128
129
130
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 126
def siblings
return [] if root?
parent.children.reject { |child| child == self }
end
|
#xccdf_type ⇒ Object
Takes the last segment of the class name, splits on captial letters, and returns a downcased string joined by dashes. This gives us the XCCDF element type. Example: ‘AbideDevUtils::XCCDF::Parser::Objects::ComplexCheck’ returns ‘complex-check’.
[View source]
59
60
61
|
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 59
def xccdf_type
self.class.name.split('::').last.split(/(?=[A-Z])/).reject { |x| x == 'Xccdf' }.join('-').downcase
end
|