Class: StatModule::Stat

Inherits:
JSONable show all
Defined in:
lib/stat.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(process) ⇒ Stat

Returns a new instance of Stat.

Raises:



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

#statVersionObject (readonly)

Returns the value of attribute statVersion.



16
17
18
# File 'lib/stat.rb', line 16

def statVersion
  @statVersion
end

Instance Method Details

#findingsObject



35
36
37
# File 'lib/stat.rb', line 35

def findings
  @findings
end

#findings=(findings) ⇒ Object

Raises:



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


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


72
73
74
75
76
# File 'lib/stat.rb', line 72

def print_footer
  @finding_print_index = 0
  puts ']}'
  puts
end


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

#processObject



44
45
46
# File 'lib/stat.rb', line 44

def process
  @process
end

#process=(process) ⇒ Object

Raises:



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(options = {})
  super(['finding_print_index'])
end