Class: Polytrix::Reporters::HashReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/polytrix/reporters/hash_reporter.rb

Direct Known Subclasses

JSONReporter, YAMLReporter

Instance Method Summary collapse

Constructor Details

#initialize(io = $stdout) ⇒ HashReporter

Returns a new instance of HashReporter.



6
7
8
# File 'lib/polytrix/reporters/hash_reporter.rb', line 6

def initialize(io = $stdout)
  @buffer = io
end

Instance Method Details

#colors?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/polytrix/reporters/hash_reporter.rb', line 27

def colors?
  false
end

#convert(_data) ⇒ Object



23
24
25
# File 'lib/polytrix/reporters/hash_reporter.rb', line 23

def convert(_data)
  fail 'Subclass HashReporter and convert the data to the target format'
end


10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/polytrix/reporters/hash_reporter.rb', line 10

def print_table(table)
  headers = table[0]
  data = []
  table[1..-1].map do |row|
    row_data = {}
    row.each_with_index do |value, index|
      row_data[headers[index]] = value
    end
    data << row_data
  end
  @buffer.puts convert(data)
end