Class: TableSyntax::HeaderTable
- Inherits:
-
Object
- Object
- TableSyntax::HeaderTable
- Includes:
- Enumerable
- Defined in:
- lib/table_syntax/header_table.rb
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(headers, table) ⇒ HeaderTable
constructor
A new instance of HeaderTable.
Constructor Details
#initialize(headers, table) ⇒ HeaderTable
Returns a new instance of HeaderTable.
5 6 7 8 9 10 11 |
# File 'lib/table_syntax/header_table.rb', line 5 def initialize(headers, table) unless headers.all? {|h| h.kind_of?(Symbol) } raise ArgumentError, "All headers must be symbols" end @struct = Struct.new(*headers) @rows = table.to_a end |
Instance Method Details
#each ⇒ Object
13 14 15 16 17 18 |
# File 'lib/table_syntax/header_table.rb', line 13 def each return enum_for(:each) unless block_given? @rows.each do |row| yield @struct.new(*row) end end |