Class: StatModule::Stat

Inherits:
JSONable show all
Defined in:
lib/structured-acceptance-test.rb

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

Initialize new Stat object

Params:

process

StatModule::Process, required

hash

Hash, can be null

Raises:



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/structured-acceptance-test.rb', line 24

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

#statVersionObject (readonly)

Returns the value of attribute statVersion.



16
17
18
# File 'lib/structured-acceptance-test.rb', line 16

def statVersion
  @statVersion
end

Instance Method Details

#findingsObject

Get array of findings



54
55
56
# File 'lib/structured-acceptance-test.rb', line 54

def findings
  @findings
end

#findings=(findings) ⇒ Object

Set array of findings

Params:

findings

Array of StatModule::Finding

Raises:



43
44
45
46
47
48
49
50
# File 'lib/structured-acceptance-test.rb', line 43

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

Prints one finding in json format.



92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/structured-acceptance-test.rb', line 92

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

Prints footer of STAT object in json format



107
108
109
110
111
112
# File 'lib/structured-acceptance-test.rb', line 107

def print_footer
  @finding_print_index = 0
  puts ']}'
  puts
  $stdout.flush
end

Prints header of STAT object in json format Header contains statVersion, process and optional array of findings



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/structured-acceptance-test.rb', line 77

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

#processObject

Get process



70
71
72
# File 'lib/structured-acceptance-test.rb', line 70

def process
  @process
end

#process=(process) ⇒ Object

Set process

Params:

process

instance of StatModule::Process

Raises:



63
64
65
66
# File 'lib/structured-acceptance-test.rb', line 63

def process=(process)
  raise TypeException unless process.is_a?(StatModule::Process)
  @process = process
end

#summary_print(formatted = false) ⇒ Object

Get statistic information about findings

Params:

formatted

indicate weather print boring or pretty colorful statistic



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/structured-acceptance-test.rb', line 126

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

Get STAT object in json format



116
117
118
# File 'lib/structured-acceptance-test.rb', line 116

def to_json(options = {})
  super(['finding_print_index'])
end