Sha256: c1ee351383b2f68cb91fa5bd1bc78ef4f5a8197256435fa9649a5c2fd3a79f65

Contents?: true

Size: 915 Bytes

Versions: 1

Compression:

Stored size: 915 Bytes

Contents

# encoding: UTF-8

require 'active_support/all'

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] || false
      a = to_table.to_a
      data = a.transpose
      data.unshift((1..a.length).to_a) if with_indices
      data.each_with_index.map { |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 { |cell, i|
          i.zero? ? cell.to_s.center(w) : cell.to_s.ljust(w) } # alligns the column #
      }.transpose.map { |row| "[#{row.join(' | ')}]" }.unshift('').join("\n")
    end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gooddata-0.6.0 lib/gooddata/models/data_result.rb