Class: Util::ExtractNistMappings

Inherits:
Object
  • Object
show all
Defined in:
lib/utilities/extract_nist_cis_mapping.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ ExtractNistMappings

Returns a new instance of ExtractNistMappings.



5
6
7
8
9
10
11
12
13
14
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 5

def initialize(file)
  @file = file
  @full_excel = []
  @headers = {}

  open_excel
  set_working_sheet
  map_headers
  retrieve_mappings
end

Instance Method Details

#full_exclObject



20
21
22
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 20

def full_excl
  @full_excel
end

#map_headersObject



28
29
30
31
32
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 28

def map_headers
  @xlsx.row(3).each_with_index { |header, i|
    @headers[header] = i
  }
end

#open_excelObject



16
17
18
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 16

def open_excel
  @xlsx = Roo::Excelx.new(@file)
end

#retrieve_mappingsObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 34

def retrieve_mappings
  nist_ver = 4
  cis_ver = @xlsx.row(2)[4].split(' ')[-1]
  ctrl_count = 1
  ((@xlsx.first_row + 3)..@xlsx.last_row).each do |row_value|
    current_row = {}
    if @xlsx.row(row_value)[@headers['NIST SP 800-53 Control #']].to_s != ''
      current_row[:nist] = @xlsx.row(row_value)[@headers['NIST SP 800-53 Control #']].to_s
    else
      current_row[:nist] = 'Not Mapped'
    end
    current_row[:nist_ver] = nist_ver
    if @xlsx.row(row_value)[@headers['Control']].to_s == ''
      current_row[:cis] = ctrl_count.to_s
      ctrl_count += 1
    else
      current_row[:cis] = @xlsx.row(row_value)[@headers['Control']].to_s
    end
    current_row[:cis_ver] = cis_ver
    @full_excel << current_row
  end
end

#set_working_sheetObject



24
25
26
# File 'lib/utilities/extract_nist_cis_mapping.rb', line 24

def set_working_sheet
  @xlsx.default_sheet = 'VER 6.1 Controls'
end