Sha256: 964351af3509d7745ca05f5a107680830cb8fed8920130e091d4f068f2aedd6d

Contents?: true

Size: 593 Bytes

Versions: 2

Compression:

Stored size: 593 Bytes

Contents

require 'csv'

module Polytrix
  module Reports
    class HashReporter
      def initialize(io = $stdout)
        @buffer = io
      end

      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

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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
polytrix-0.1.2 lib/polytrix/reports/hash_reporter.rb
polytrix-0.1.1 lib/polytrix/reports/hash_reporter.rb