Sha256: c54cc7844e3a847e1be5ddb263d5830111f0be0e7f6899d96dfb3e191c78e9fd

Contents?: true

Size: 930 Bytes

Versions: 6

Compression:

Stored size: 930 Bytes

Contents

# encoding: UTF-8

require_relative '../extensions/big_decimal'

module GoodData
  class DataResult
    attr_reader :data

    def initialize(data)
      @data = data
    end

    def print
      puts to_s
    end

    def to_s(options = {})
      with_indices = options[:index]

      a = to_table.to_a
      data = a.transpose
      data.unshift((1..a.length).to_a) if with_indices
      processed_data = data.each_with_index.map do |col, i|
        col.unshift(i.zero? ? nil : i) if with_indices # inserts row labels #
        w = col.map { |cell| cell.to_s.length }.max # w = "column width" #
        col.each_with_index.map do |cell, j|
          j.zero? ? cell.to_s.center(w) : cell.to_s.ljust(w)
        end # alligns the column #
      end
      processed_data.transpose.map { |row| "[#{row.join(' | ')}]" }.unshift('').join("\n")
    end

    def to_table
      fail 'Should be implemented in subclass'
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gooddata-0.6.7 lib/gooddata/models/data_result.rb
gooddata-0.6.6 lib/gooddata/models/data_result.rb
gooddata-0.6.5 lib/gooddata/models/data_result.rb
gooddata-0.6.4 lib/gooddata/models/data_result.rb
gooddata-0.6.3 lib/gooddata/models/data_result.rb
gooddata-0.6.2 lib/gooddata/models/data_result.rb