Class: AbideDevUtils::XCCDF::Parser::Objects::Benchmark

Inherits:
ElementBase
  • Object
show all
Includes:
NumberedObject
Defined in:
lib/abide_dev_utils/xccdf/parser/objects.rb

Overview

Class for XCCDF benchmark

Constant Summary

Constants inherited from ElementBase

ElementBase::UNICODE_SYMBOLS

Instance Attribute Summary

Attributes inherited from ElementBase

#child_labels, #children, #link_labels, #links, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NumberedObject

#<=>, #find_child_by_number, #number_child_of?, #number_eq, #number_gt, #number_lt, #number_parent_of?, #search_children_by_number

Methods inherited from ElementBase

#<=>, #add_link, #add_links, #all_values, #ancestors, #depth, #descendants, #find_similarity, #inspect, #label, #leaf?, #print_tree, #root, #root?, #siblings, #xccdf_type, xmlns

Methods included from Helpers::XPath

#find_element

Methods included from DiffableObject

#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(element, parent_node: nil) ⇒ Benchmark

Returns a new instance of Benchmark.



954
955
956
957
958
959
960
961
962
963
964
965
966
967
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 954

def initialize(element, parent_node: nil)
  super
  elem = find_element.at_xpath(element, 'Benchmark')
  raise 'No Benchmark element found' if elem.nil?

  add_child(Status, elem)
  add_child(Title, elem)
  add_child(Description, elem)
  add_child(Platform, elem)
  add_child(Version, elem)
  add_children(Profile, elem)
  add_children(Group, elem)
  add_children(Value, elem)
end

Class Method Details

.xpathObject



997
998
999
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 997

def self.xpath
  'Benchmark'
end

Instance Method Details

#diff_only_rules(other, profile: nil, level: nil) ⇒ Object



985
986
987
988
989
990
991
992
993
994
995
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 985

def diff_only_rules(other, profile: nil, level: nil)
  self_rules = descendants.select { |x| x.is_a?(Rule) }
  other_rules = other.descendants.select { |x| x.is_a?(Rule) }
  unless profile.nil?
    self_rules = self_rules.select { |x| x.linked_profile.any? { |p| p.title.to_s.match?(profile) } }
  end
  unless level.nil?
    self_rules = self_rules.select { |x| x.linked_profile.any? { |p| p.level.to_s.match?(level) } }
  end
  diff_array_obj(self_rules, other_rules)
end

#numberObject



969
970
971
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 969

def number
  @number ||= version.to_s[/([0-9]+\.)+[0-9]+/]
end

#to_hObject



973
974
975
976
977
978
979
980
981
982
983
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 973

def to_h
  {
    title: title.to_s,
    version: version.to_s,
    status: status.to_s,
    platform: platform.to_s,
    profile: profile.map(&:to_h),
    group: group.map(&:to_h),
    value: value.map(&:to_h),
  }
end

#to_sObject



1001
1002
1003
# File 'lib/abide_dev_utils/xccdf/parser/objects.rb', line 1001

def to_s
  [title.to_s, version.to_s].join(' ')
end