Sha256: e05e9cd4cdd6c03892e8df8fd33f541588d04fbec11e27a1ce368bad466c2b80

Contents?: true

Size: 1.61 KB

Versions: 3

Compression:

Stored size: 1.61 KB

Contents

# encoding: UTF-8

module GoodData
  module Model
    class SchemaBuilder
      attr_accessor :data

      class << self
        def create_from_data(blueprint)
          sc = SchemaBuilder.new
          sc.data = blueprint.to_hash
          sc
        end
      end

      def initialize(name = nil)
        @data = {
          :name => name,
          :columns => []
        }
      end

      def name
        data[:name]
      end

      def columns
        data[:columns]
      end

      def add_column(column_def)
        columns.push(column_def)
        self
      end

      def add_anchor(name, options = {})
        add_column({ :type => :anchor, :name => name }.merge(options))
        self
      end

      def add_attribute(name, options = {})
        add_column({ :type => :attribute, :name => name }.merge(options))
        self
      end

      def add_fact(name, options = {})
        add_column({ :type => :fact, :name => name }.merge(options))
        self
      end

      def add_label(name, options = {})
        add_column({ :type => :label, :name => name }.merge(options))
        self
      end

      def add_date(name, options = {})
        add_column({ :type => :date, :name => name }.merge(options))
      end

      def add_reference(name, options = {})
        add_column({ :type => :reference, :name => name }.merge(options))
      end

      def to_json
        JSON.pretty_generate(to_hash)
      end

      def to_hash
        data
      end

      def to_blueprint
        GoodData::Model::DatasetBlueprint.new(to_hash)
      end

      def to_schema
        Schema.new(to_hash)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

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