Class: AbideDevUtils::XCCDF::Utils::FileDir

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/xccdf/utils.rb

Overview

Class for working with directories that contain XCCDF files

Constant Summary collapse

CIS_FILE_NAME_PARTS_PATTERN =
/^CIS_(?<subject>[A-Za-z0-9._()-]+)_Benchmark_v(?<version>[0-9.]+)-xccdf$/.freeze

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ FileDir

Returns a new instance of FileDir.



11
12
13
14
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 11

def initialize(path)
  @path = File.expand_path(path)
  AbideDevUtils::Validate.directory(@path)
end

Instance Method Details

#filesObject



16
17
18
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 16

def files
  @files ||= Dir.glob(File.join(@path, '*-xccdf.xml')).map { |f| FileNameData.new(f) }
end

#fuzzy_find(label, value) ⇒ Object



20
21
22
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 20

def fuzzy_find(label, value)
  files.find { |f| f.fuzzy_match?(label, value) }
end

#fuzzy_reject(label, value) ⇒ Object



28
29
30
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 28

def fuzzy_reject(label, value)
  files.reject { |f| f.fuzzy_match?(label, value) }
end

#fuzzy_select(label, value) ⇒ Object



24
25
26
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 24

def fuzzy_select(label, value)
  files.select { |f| f.fuzzy_match?(label, value) }
end

#label?(label) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 32

def label?(label)
  files.select { |f| f.has?(label) }
end

#no_label?(label) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/abide_dev_utils/xccdf/utils.rb', line 36

def no_label?(label)
  files.reject { |f| f.has?(label) }
end