Class: TableStructure::Schema::Table

Inherits:
Object
  • Object
show all
Defined in:
lib/table_structure/schema/table.rb

Constant Summary collapse

RESULT_BUILDERS =
{
  hash: lambda { |values, keys, *|
    keys.map.with_index { |key, i| [key || i, values[i]] }.to_h
  }
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, column_definitions, column_converters, result_builders, context, options) ⇒ Table

Returns a new instance of Table.



14
15
16
17
18
19
20
21
# File 'lib/table_structure/schema/table.rb', line 14

def initialize(name, column_definitions, column_converters, result_builders, context, options)
  @name = name
  @columns = build_columns(name, column_definitions, context, options)
  @column_converters = column_converters
  @result_builders = result_builders
  @context = context
  @options = options
end

Instance Attribute Details

#column_convertersObject (readonly)

Returns the value of attribute column_converters.



12
13
14
# File 'lib/table_structure/schema/table.rb', line 12

def column_converters
  @column_converters
end

#columnsObject (readonly)

Returns the value of attribute columns.



12
13
14
# File 'lib/table_structure/schema/table.rb', line 12

def columns
  @columns
end

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/table_structure/schema/table.rb', line 12

def options
  @options
end

#result_buildersObject (readonly)

Returns the value of attribute result_builders.



12
13
14
# File 'lib/table_structure/schema/table.rb', line 12

def result_builders
  @result_builders
end

Instance Method Details

#header_values(context, result_type = nil) ⇒ Object

TODO



23
24
25
# File 'lib/table_structure/schema/table.rb', line 23

def header_values(context, result_type = nil) # TODO
  values(:name, result_type, context)
end

#keysObject



31
32
33
# File 'lib/table_structure/schema/table.rb', line 31

def keys
  @keys ||= @columns.map(&:key).flatten
end

#row_values(context, result_type = nil) ⇒ Object

TODO



27
28
29
# File 'lib/table_structure/schema/table.rb', line 27

def row_values(context, result_type = nil) # TODO
  values(:value, result_type, context)
end

#sizeObject



35
36
37
# File 'lib/table_structure/schema/table.rb', line 35

def size
  @size ||= @columns.map(&:size).reduce(0) { |memo, size| memo + size }
end