Sha256: b86a56f19c6b0a26b4e400ffbf26af50049089569059dffbceffbf272d7d39f1

Contents?: true

Size: 979 Bytes

Versions: 9

Compression:

Stored size: 979 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

9 entries across 9 versions & 1 rubygems

Version Path
gooddata-0.6.20 lib/gooddata/models/data_result.rb
gooddata-0.6.19 lib/gooddata/models/data_result.rb
gooddata-0.6.18 lib/gooddata/models/data_result.rb
gooddata-0.6.17 lib/gooddata/models/data_result.rb
gooddata-0.6.16 lib/gooddata/models/data_result.rb
gooddata-0.6.15 lib/gooddata/models/data_result.rb
gooddata-0.6.14 lib/gooddata/models/data_result.rb
gooddata-0.6.13 lib/gooddata/models/data_result.rb
gooddata-0.6.12 lib/gooddata/models/data_result.rb