Class: OCTool::System
- Inherits:
-
Object
- Object
- OCTool::System
- 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
-
#config ⇒ Object
Returns the value of attribute config.
-
#data ⇒ Object
Returns the value of attribute data.
Instance Method Summary collapse
- #acronyms ⇒ Object
-
#attestations ⇒ Object
List of all attestations claimed by components in the system.
- #certifications ⇒ Object
- #components ⇒ Object
-
#controls ⇒ Object
List of all controls defined by standards in the system.
- #dump(writable_dir) ⇒ Object
-
#families ⇒ Object
List of all families defined by standards in the system.
-
#initialize(config) ⇒ System
constructor
A new instance of System.
-
#requires ⇒ Object
List of required controls for all certifications.
-
#satisfies ⇒ Object
List of all coverages.
- #standards ⇒ Object
-
#write_csv(ary, filename) ⇒ Object
Convert array of hashes into a CSV.
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
#config ⇒ Object
Returns the value of attribute config.
6 7 8 |
# File 'lib/octool/system.rb', line 6 def config @config end |
#data ⇒ Object
Returns the value of attribute data.
7 8 9 |
# File 'lib/octool/system.rb', line 7 def data @data end |
Instance Method Details
#acronyms ⇒ Object
25 26 27 |
# File 'lib/octool/system.rb', line 25 def acronyms @acronyms ||= config['acronyms'] end |
#attestations ⇒ Object
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 |
#certifications ⇒ Object
29 30 31 |
# File 'lib/octool/system.rb', line 29 def certifications @certifications ||= data.select { |e| e['type'] == 'certification' } end |
#components ⇒ Object
33 34 35 |
# File 'lib/octool/system.rb', line 33 def components @components ||= data.select { |e| e['type'] == 'component' } end |
#controls ⇒ Object
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 |
#families ⇒ Object
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 |
#requires ⇒ Object
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 |
#satisfies ⇒ Object
List of all coverages.
47 48 49 |
# File 'lib/octool/system.rb', line 47 def satisfies @satisfies ||= attestations.map { |a| a['satisfies'] }.flatten end |
#standards ⇒ Object
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 |