Class: ArrayFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/teuton/report/formatter/array_formatter.rb

Overview

ArrayFormatter class: format report data into an array

Instance Method Summary collapse

Methods inherited from BaseFormatter

#deinit, #init, #trim, #w

Constructor Details

#initialize(report) ⇒ ArrayFormatter

Returns a new instance of ArrayFormatter.



7
8
9
10
# File 'lib/teuton/report/formatter/array_formatter.rb', line 7

def initialize(report)
  super(report)
  @data = {}
end

Instance Method Details

#build_dataObject



18
19
20
21
22
23
# File 'lib/teuton/report/formatter/array_formatter.rb', line 18

def build_data
  build_initial_data
  build_history_data
  build_final_data
  build_hof_data
end

#build_final_dataObject



70
71
72
73
74
# File 'lib/teuton/report/formatter/array_formatter.rb', line 70

def build_final_data
  tail = {}
  @tail.each { |key, value| tail[key] = value }
  @data[:results] = tail
end

#build_history_dataObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/teuton/report/formatter/array_formatter.rb', line 31

def build_history_data
  @data[:logs] = []
  groups = []
  title = nil
  targets = []
  @lines.each do |i|
    if i.class.to_s == 'Hash'
      value = 0.0
      value = i[:weight] if i[:check]
      if i[:groupname] != title
        # Add currentgroup
        groups << { title: title, targets: targets } unless title.nil?
        # Create new group
        title = i[:groupname]
        targets = []
      end

      target = {}
      target[:target_id]   = format('%02d', i[:id])
      target[:check]       = i[:check]
      target[:score]       = value
      target[:weight]      = i[:weight]
      target[:description] = i[:description]
      target[:command]     = i[:command]
      target[:conn_type]   = i[:conn_type]
      target[:duration]    = i[:duration]
      target[:alterations] = i[:alterations]
      target[:expected]    = i[:expected]
      target[:result]      = i[:result]
      targets << target
    else
      @data[:logs] << i.to_s # Add log line
    end
  end

  groups << { title: title, targets: targets } unless title.nil?
  @data[:groups] = groups
end

#build_hof_dataObject



76
77
78
79
80
81
82
83
# File 'lib/teuton/report/formatter/array_formatter.rb', line 76

def build_hof_data
  app = Application.instance
  @data[:hall_of_fame] = {}
  return if app.options[:case_number] < 3
  fame = {}
  app.hall_of_fame.each { |line| fame[line[0]] = line[1] }
  @data[:hall_of_fame] = fame
end

#build_initial_dataObject



25
26
27
28
29
# File 'lib/teuton/report/formatter/array_formatter.rb', line 25

def build_initial_data
  head = {}
  @head.each { |key, value| head[key] = value }
  @data[:config] = head
end

#processObject



12
13
14
15
16
# File 'lib/teuton/report/formatter/array_formatter.rb', line 12

def process
  build_data
  w @data.to_s # Write data into ouput file
  deinit
end