Class: OCTool::System

Inherits:
Object
  • Object
show all
Defined in:
lib/octool/system.rb

Overview

Representation of a system

Constant Summary collapse

TABLE_NAMES =
[
    'components',
    'satisfies',
    'attestations',
    'standards',
    'controls',
    'families',
    'certifications',
    'requires',
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ System

Returns a new instance of System.



20
21
22
23
# File 'lib/octool/system.rb', line 20

def initialize(config)
    @config = config
    @data = []
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



6
7
8
# File 'lib/octool/system.rb', line 6

def config
  @config
end

#dataObject

Returns the value of attribute data.



7
8
9
# File 'lib/octool/system.rb', line 7

def data
  @data
end

Instance Method Details

#acronymsObject



25
26
27
# File 'lib/octool/system.rb', line 25

def acronyms
    @acronyms ||= config['acronyms']
end

#attestationsObject

List of all attestations claimed by components in the system.



42
43
44
# File 'lib/octool/system.rb', line 42

def attestations
    @attestations ||= components.map { |c| c['attestations'] }.flatten
end

#certificationsObject



29
30
31
# File 'lib/octool/system.rb', line 29

def certifications
    @certifications ||= data.select { |e| e['type'] == 'certification' }
end

#componentsObject



33
34
35
# File 'lib/octool/system.rb', line 33

def components
    @components ||= data.select { |e| e['type'] == 'component' }
end

#controlsObject

List of all controls defined by standards in the system.



52
53
54
# File 'lib/octool/system.rb', line 52

def controls
    @controls ||= standards.map { |s| s['controls'] }.flatten
end

#dump(writable_dir) ⇒ Object



66
67
68
69
70
# File 'lib/octool/system.rb', line 66

def dump(writable_dir)
    TABLE_NAMES.each do |table|
        write_csv method(table.to_sym).call, File.join(writable_dir, "#{table}.csv")
    end
end

#familiesObject

List of all families defined by standards in the system.



57
58
59
# File 'lib/octool/system.rb', line 57

def families
    @families ||= standards.map { |s| s['families'] }.flatten
end

#requiresObject

List of required controls for all certifications.



62
63
64
# File 'lib/octool/system.rb', line 62

def requires
    @requires ||= certifications.map { |c| c['requires'] }.flatten
end

#satisfiesObject

List of all coverages.



47
48
49
# File 'lib/octool/system.rb', line 47

def satisfies
    @satisfies ||= attestations.map { |a| a['satisfies'] }.flatten
end

#standardsObject



37
38
39
# File 'lib/octool/system.rb', line 37

def standards
    @standards ||= data.select { |e| e['type'] == 'standard' }
end

#write_csv(ary, filename) ⇒ Object

Convert array of hashes into a CSV.



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/octool/system.rb', line 73

def write_csv(ary, filename)
    # Throw away nested hashes. The parser already created separate tables for them.
    ary = ary.map { |e| e.reject { |_, val| val.is_a?(Enumerable) } }

    warn "[INFO] write #{filename}"
    CSV.open(filename, 'wb') do |csv|
        column_names = ary.first.keys
        csv << column_names
        ary.each { |hash| csv << hash.values_at(*column_names) }
    end
end