Sha256: 2e79893e7e7e39f791a5ba0258cbf618db527c0cc6f4015d97934d1ac8cbd8d9

Contents?: true

Size: 980 Bytes

Versions: 4

Compression:

Stored size: 980 Bytes

Contents

# encoding: UTF-8

require_relative '../extensions/big_decimal'

require_relative '../rest/object'

module GoodData
  class DataResult < Rest::Object
    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

4 entries across 4 versions & 1 rubygems

Version Path
gooddata-0.6.11 lib/gooddata/models/data_result.rb
gooddata-0.6.10 lib/gooddata/models/data_result.rb
gooddata-0.6.9 lib/gooddata/models/data_result.rb
gooddata-0.6.8 lib/gooddata/models/data_result.rb