Sha256: 552e9af50565eac55990da25cc9ae7e205958c5ea1c6fdb330999817fe572f6e

Contents?: true

Size: 1.51 KB

Versions: 3

Compression:

Stored size: 1.51 KB

Contents

# encoding: UTF-8

require_relative '../metadata/column'
require_relative 'label'

module GoodData
  module Model
    ##
    # GoodData attribute abstraction
    #
    class Attribute < Column
      attr_reader :primary_label, :labels

      def type_prefix
        ATTRIBUTE_PREFIX
      end

      def folder_prefix
        ATTRIBUTE_FOLDER_PREFIX
      end

      def initialize(hash, schema)
        super hash, schema
        @labels = []
        @primary_label = Label.new hash, self, schema
      end

      def table
        @table ||= 'd_' + @schema.name + '_' + name
      end

      def key
        "#{@name}#{FK_SUFFIX}"
      end

      def to_maql_create
        maql = "CREATE ATTRIBUTE {#{identifier}} VISUAL (#{visual})" \
               + " AS KEYS {#{table}.#{Model::FIELD_PK}} FULLSET;\n"
        maql += @primary_label.to_maql_create if @primary_label
        maql
      end

      def to_manifest_part(mode)
        {
          'referenceKey' => 1,
          'populates' => [@primary_label.identifier],
          'mode' => mode,
          'columnName' => name
        }
      end

      def to_wire_model
        {
          'attribute' => {
            'identifier' => identifier,
            'title' => title,
            'labels' => labels.map do |l|
              {
                'label' => {
                  'identifier' => l.identifier,
                  'title' => l.title,
                  'type' => 'GDC.text'
                }
              }
            end
          }
        }
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gooddata-0.6.4 lib/gooddata/models/columns/attribute.rb
gooddata-0.6.3 lib/gooddata/models/columns/attribute.rb
gooddata-0.6.2 lib/gooddata/models/columns/attribute.rb