Class: StatModule::Stat
Instance Attribute Summary collapse
-
#statVersion ⇒ Object
readonly
Returns the value of attribute statVersion.
Instance Method Summary collapse
- #findings ⇒ Object
- #findings=(findings) ⇒ Object
-
#initialize(process) ⇒ Stat
constructor
A new instance of Stat.
- #print_finding ⇒ Object
- #print_footer ⇒ Object
- #print_header ⇒ Object
- #process ⇒ Object
- #process=(process) ⇒ Object
- #to_json(options = {}) ⇒ Object
Constructor Details
#initialize(process) ⇒ Stat
Returns a new instance of Stat.
18 19 20 21 22 23 24 |
# File 'lib/stat.rb', line 18 def initialize(process) raise TypeException unless process.is_a?(StatModule::Process) @statVersion = '1.0.0' @process = process @findings = [] @finding_print_index = 0 end |
Instance Attribute Details
#statVersion ⇒ Object (readonly)
Returns the value of attribute statVersion.
16 17 18 |
# File 'lib/stat.rb', line 16 def statVersion @statVersion end |
Instance Method Details
#findings ⇒ Object
35 36 37 |
# File 'lib/stat.rb', line 35 def findings @findings end |
#findings=(findings) ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/stat.rb', line 26 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 ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/stat.rb', line 60 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 @finding_print_index += 1 else raise IndexOutOfBoundException end end |
#print_footer ⇒ Object
72 73 74 75 76 |
# File 'lib/stat.rb', line 72 def @finding_print_index = 0 puts ']}' puts end |
#print_header ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/stat.rb', line 48 def print_header @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 end |
#process ⇒ Object
44 45 46 |
# File 'lib/stat.rb', line 44 def process @process end |
#process=(process) ⇒ Object
39 40 41 42 |
# File 'lib/stat.rb', line 39 def process=(process) raise TypeException unless process.is_a?(StatModule::Process) @process = process end |
#to_json(options = {}) ⇒ Object
78 79 80 |
# File 'lib/stat.rb', line 78 def to_json( = {}) super(['finding_print_index']) end |