Class: RuleResult

Inherits:
Object
  • Object
show all
Defined in:
lib/audit/lib/benchmark/rule_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rule, results) ⇒ RuleResult

Returns a new instance of RuleResult.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/audit/lib/benchmark/rule_result.rb', line 13

def initialize(rule, results)
  @timestamp = Time.now.utc
#    @severity = rule.severity
#    @version = rule.version

  return_codes = results.reject {|x| x.type != ResultType::CHECK_FINISHED}
  raise "Each rule should have exacty one return code" if return_codes.length != 1
  return_code = return_codes[0]

  if return_code.exit_code.downcase == "pass" then
    @result = ResultCode::PASS
  else
    @result = ResultCode::FAIL
  end

  @rule_idref = rule.id
  @rule = rule
  @check = results
end

Instance Attribute Details

#checkObject (readonly)

Returns the value of attribute check.



6
7
8
# File 'lib/audit/lib/benchmark/rule_result.rb', line 6

def check
  @check
end

#resultObject (readonly)

Returns the value of attribute result.



8
9
10
# File 'lib/audit/lib/benchmark/rule_result.rb', line 8

def result
  @result
end

#ruleObject (readonly)

Returns the value of attribute rule.



5
6
7
# File 'lib/audit/lib/benchmark/rule_result.rb', line 5

def rule
  @rule
end

#rule_idrefObject (readonly)

Returns the value of attribute rule_idref.



7
8
9
# File 'lib/audit/lib/benchmark/rule_result.rb', line 7

def rule_idref
  @rule_idref
end

#severityObject (readonly)

Returns the value of attribute severity.



11
12
13
# File 'lib/audit/lib/benchmark/rule_result.rb', line 11

def severity
  @severity
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/audit/lib/benchmark/rule_result.rb', line 10

def timestamp
  @timestamp
end

#versionObject (readonly)

Returns the value of attribute version.



9
10
11
# File 'lib/audit/lib/benchmark/rule_result.rb', line 9

def version
  @version
end

Instance Method Details

#to_hashObject



33
34
35
36
37
38
39
40
41
# File 'lib/audit/lib/benchmark/rule_result.rb', line 33

def to_hash()
  return {
    :type => :RULE_RESULT,
    :timestamp => @timestamp,
    :rule => @rule_idref,
    :checks => Lazy.new(@check, :map) {|result| Lazy.new(result, :to_hash)},
    :result => @result
  }
end