Class: Mode::Sdk::ColumnSet

Inherits:
Object
  • Object
show all
Defined in:
lib/mode/sdk/column_set.rb

Overview

Represents a set of Mode::Column instances

Defined Under Namespace

Classes: InvalidError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_columns) ⇒ Mode::Sdk::ColumnSet

Construct a new ColumnSet instance

Parameters:

  • original_columns (Array<Hash>)

    an array of hashes defining column names and types


17
18
19
# File 'lib/mode/sdk/column_set.rb', line 17

def initialize(original_columns)
  @original_columns = original_columns
end

Instance Attribute Details

#original_columnsObject (readonly)

Returns the value of attribute original_columns


8
9
10
# File 'lib/mode/sdk/column_set.rb', line 8

def original_columns
  @original_columns
end

Instance Method Details

#columnsArray<Mode::Sdk::Column>

Build an array of Mode::Sdk::Column instances

Returns:


25
26
27
28
29
# File 'lib/mode/sdk/column_set.rb', line 25

def columns
  @columns ||= (original_columns || []).map do |column|
    Mode::Sdk::Column.new(column)
  end
end

#to_arrayArray<Hash>

Convert columns to array of hashes

Returns:

  • (Array<Hash>)

    array of column attribute hashes


49
50
51
# File 'lib/mode/sdk/column_set.rb', line 49

def to_array
  columns.map(&:attributes)
end

#validate!true

Validate the provided columns

Returns:

  • (true)

Raises:


37
38
39
40
41
42
43
# File 'lib/mode/sdk/column_set.rb', line 37

def validate!
  fail InvalidError, 'No columns provided' unless columns.any?

  columns.each(&:validate!)

  true
end