Class: Inspec::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/objects/control.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeControl

Returns a new instance of Control.



6
7
8
# File 'lib/inspec/objects/control.rb', line 6

def initialize
  @tests = []
end

Instance Attribute Details

#descObject

Returns the value of attribute desc.



5
6
7
# File 'lib/inspec/objects/control.rb', line 5

def desc
  @desc
end

#idObject

Returns the value of attribute id.



5
6
7
# File 'lib/inspec/objects/control.rb', line 5

def id
  @id
end

#impactObject

Returns the value of attribute impact.



5
6
7
# File 'lib/inspec/objects/control.rb', line 5

def impact
  @impact
end

#testsObject

Returns the value of attribute tests.



5
6
7
# File 'lib/inspec/objects/control.rb', line 5

def tests
  @tests
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/inspec/objects/control.rb', line 5

def title
  @title
end

Instance Method Details

#add_test(t) ⇒ Object



10
11
12
# File 'lib/inspec/objects/control.rb', line 10

def add_test(t)
  @tests.push(t)
end

#to_hashObject



14
15
16
# File 'lib/inspec/objects/control.rb', line 14

def to_hash
  { id: id, title: title, desc: desc, impact: impact, tests: tests.map(&:to_hash) }
end

#to_rubyObject



18
19
20
21
22
23
24
25
26
# File 'lib/inspec/objects/control.rb', line 18

def to_ruby
  res = ["control #{id.inspect} do"]
  res.push "  title #{title.inspect}" unless title.to_s.empty?
  res.push "  desc  #{desc.inspect}" unless desc.to_s.empty?
  res.push "  impact #{impact}" unless impact.nil?
  tests.each { |t| res.push(indent(t.to_ruby, 2)) }
  res.push 'end'
  res.join("\n")
end