Class: StatModule::Stat
Constant Summary
Constants inherited
from JSONable
JSONable::FORMATTING_BALL, JSONable::FORMATTING_CHECKMARK, JSONable::FORMATTING_STAR, JSONable::FORMATTING_WARNING
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods inherited from JSONable
from_json!
Constructor Details
#initialize(process, hash = nil) ⇒ Stat
Returns a new instance of Stat.
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/stat.rb', line 18
def initialize(process, hash = nil)
@finding_print_index = 0
@findings = []
if hash.is_a? Hash
super(hash)
return
end
raise TypeException unless process.is_a?(StatModule::Process)
@statVersion = '1.0.0'
@process = process
end
|
Instance Attribute Details
#statVersion ⇒ Object
Returns the value of attribute statVersion.
16
17
18
|
# File 'lib/stat.rb', line 16
def statVersion
@statVersion
end
|
Instance Method Details
#findings ⇒ Object
41
42
43
|
# File 'lib/stat.rb', line 41
def findings
@findings
end
|
#findings=(findings) ⇒ Object
#print_finding ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/stat.rb', line 67
def print_finding
if @finding_print_index < @findings.length
result = @findings[@finding_print_index].to_json
result += ',' unless @finding_print_index >= @findings.length - 1
puts(result)
puts
$stdout.flush
@finding_print_index += 1
else
raise IndexOutOfBoundException
end
end
|
80
81
82
83
84
85
|
# File 'lib/stat.rb', line 80
def
@finding_print_index = 0
puts ']}'
puts
$stdout.flush
end
|
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/stat.rb', line 54
def
@finding_print_index = 0
hash = {}
hash['statVersion'] = @statVersion
hash['process'] = @process.to_json
hash['findings'] = []
result = hash.to_json.to_s
result = result[0..result.length - 3]
puts(result)
puts
$stdout.flush
end
|
#process ⇒ Object
50
51
52
|
# File 'lib/stat.rb', line 50
def process
@process
end
|
#process=(process) ⇒ Object
#summary_print(formatted = false) ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/stat.rb', line 91
def summary_print(formatted = false)
errors = 0
warnings = 0
findings.each { |finding|
if finding.failure
errors += 1
else
warnings += 1
end
}
if errors == 0 && warnings == 0
result = "#{FORMATTING_CHECKMARK} PASSED with no warning".colorize(:green)
elsif errors == 0
result = "#{FORMATTING_WARNING} PASSED with #{warnings} warning".colorize(:yellow)
elsif warnings == 0
result = "#{FORMATTING_BALL} FAILED with #{errors} error".colorize(:red)
else
result = "#{FORMATTING_BALL} FAILED with #{errors} error and #{warnings} warning".colorize(:red)
end
if formatted
result
else
result[result.index(' ') + 1..result.length]
end
end
|
#to_json(options = {}) ⇒ Object
87
88
89
|
# File 'lib/stat.rb', line 87
def to_json(options = {})
super(['finding_print_index'])
end
|