Class: Tablecloth::TableDefinition
- Inherits:
-
Object
- Object
- Tablecloth::TableDefinition
- Defined in:
- lib/tablecloth/table_definition.rb
Defined Under Namespace
Classes: Column
Constant Summary collapse
- UnknownColumn =
Class.new(StandardError)
Instance Method Summary collapse
- #[](name) ⇒ Object
- #column(name, type:, from: name, retain_previous_value: false) ⇒ Object
- #column_names ⇒ Object
-
#initialize ⇒ TableDefinition
constructor
A new instance of TableDefinition.
- #mapping ⇒ Object
Constructor Details
#initialize ⇒ TableDefinition
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_names ⇒ Object
18 19 20 |
# File 'lib/tablecloth/table_definition.rb', line 18 def column_names @columns.map(&:first) end |
#mapping ⇒ Object
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 |