class StatModule::Stat
Attributes
statVersion[R]
Public Class Methods
new(process, hash = nil)
click to toggle source
Calls superclass method
StatModule::JSONable::new
# 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
Public Instance Methods
findings()
click to toggle source
# File lib/stat.rb, line 41 def findings @findings end
findings=(findings)
click to toggle source
# File lib/stat.rb, line 32 def findings=(findings) raise TypeException unless findings.is_a?(Array) findings.each { |item| raise TypeException unless item.is_a?(StatModule::Finding) raise DuplicateElementException if @findings.include?(item) @findings.push(item) } end
print_finding()
click to toggle source
# 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
print_header()
click to toggle source
# File lib/stat.rb, line 54 def print_header @finding_print_index = 0 hash = {} hash['statVersion'] = @statVersion hash['process'] = @process hash['findings'] = [] result = hash.to_json result = result[0..result.length - 3] puts(result) puts $stdout.flush end
process()
click to toggle source
# File lib/stat.rb, line 50 def process @process end
process=(process)
click to toggle source
# File lib/stat.rb, line 45 def process=(process) raise TypeException unless process.is_a?(StatModule::Process) @process = process end
summary_print(formatted = false)
click to toggle source
# 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 = {})
click to toggle source
Calls superclass method
StatModule::JSONable#to_json
# File lib/stat.rb, line 87 def to_json(options = {}) super(['finding_print_index']) end