Class: Tablecloth::TableDefinition

Inherits:
Object
  • Object
show all
Defined in:
lib/tablecloth/table_definition.rb

Defined Under Namespace

Classes: Column

Constant Summary collapse

UnknownColumn =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initializeTableDefinition

Returns a new instance of TableDefinition.



10
11
12
# File 'lib/tablecloth/table_definition.rb', line 10

def initialize
  @columns = {}
end

Instance Method Details

#[](name) ⇒ Object



28
29
30
# File 'lib/tablecloth/table_definition.rb', line 28

def [](name)
  @columns.fetch(name) { raise(UnknownColumn, name) }
end

#column(name, type:, from: name, retain_previous_value: false) ⇒ Object



14
15
16
# File 'lib/tablecloth/table_definition.rb', line 14

def column(name, type:, from: name, retain_previous_value: false)
  @columns[name] = Column.new(name, type, from, retain_previous_value)
end

#column_namesObject



18
19
20
# File 'lib/tablecloth/table_definition.rb', line 18

def column_names
  @columns.map(&:first)
end

#mappingObject



22
23
24
25
26
# File 'lib/tablecloth/table_definition.rb', line 22

def mapping
  @columns.each_with_object({}) do |(name, column), hash|
    hash[column.from] = name
  end
end