Class: AbideDevUtils::XCCDF::Utils::FileNameData
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::Utils::FileNameData
- Defined in:
- lib/abide_dev_utils/xccdf/utils.rb
Overview
Parses XCCDF file names into labeled parts
Constant Summary collapse
- CIS_PATTERN =
/^CIS_(?<subject>[A-Za-z0-9._()-]+?)(?<stig>_STIG)?_Benchmark_v(?<version>[0-9.]+)-xccdf$/.freeze
Instance Attribute Summary collapse
-
#labeled_parts ⇒ Object
readonly
Returns the value of attribute labeled_parts.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #fuzzy_match?(label, value) ⇒ Boolean
- #has?(label) ⇒ Boolean
-
#initialize(path) ⇒ FileNameData
constructor
A new instance of FileNameData.
- #stig ⇒ Object
- #subject ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(path) ⇒ FileNameData
Returns a new instance of FileNameData.
47 48 49 50 51 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 47 def initialize(path) @path = path @name = File.basename(path, '.xml') @labeled_parts = File.basename(name, '.xml').match(CIS_PATTERN)&.named_captures end |
Instance Attribute Details
#labeled_parts ⇒ Object (readonly)
Returns the value of attribute labeled_parts.
45 46 47 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 45 def labeled_parts @labeled_parts end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
45 46 47 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 45 def name @name end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
45 46 47 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 45 def path @path end |
Instance Method Details
#fuzzy_match?(label, value) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 70 def fuzzy_match?(label, value) return false unless has?(label) this_val = normalize_char_array(send(label.to_sym).chars) other_val = normalize_char_array(value.chars) other_val.each_with_index do |c, idx| return false unless this_val[idx] == c end true end |
#has?(label) ⇒ Boolean
65 66 67 68 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 65 def has?(label) val = send(label.to_sym) !val.nil? && !val.empty? end |
#stig ⇒ Object
57 58 59 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 57 def stig @stig ||= labeled_parts&.fetch('subject', nil) end |
#subject ⇒ Object
53 54 55 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 53 def subject @subject ||= labeled_parts&.fetch('subject', nil) end |
#version ⇒ Object
61 62 63 |
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 61 def version @version ||= labeled_parts&.fetch('version', nil) end |