Class: Tabulard::Adapters::Bare
- Inherits:
-
Object
- Object
- Tabulard::Adapters::Bare
- Includes:
- Table
- Defined in:
- lib/tabulard/adapters/bare.rb
Constant Summary
Constants included from Table
Table::COL_CONVERTER, Table::Message
Instance Attribute Summary
Attributes included from Table
Instance Method Summary collapse
- #each_header ⇒ Object
- #each_row ⇒ Object
-
#initialize(table, headers: nil, **opts) ⇒ Bare
constructor
A new instance of Bare.
Methods included from Table
#close, #closed?, col2int, int2col
Constructor Details
#initialize(table, headers: nil, **opts) ⇒ Bare
Returns a new instance of Bare.
10 11 12 13 14 15 16 17 18 |
# File 'lib/tabulard/adapters/bare.rb', line 10 def initialize(table, headers: nil, **opts) super(**opts) if (table_size = table.size).positive? init_with_filled_table(table, table_size: table_size, headers: headers) else init_with_empty_table(headers: headers) end end |
Instance Method Details
#each_header ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/tabulard/adapters/bare.rb', line 20 def each_header raise_if_closed return to_enum(:each_header) { @cols_count } unless block_given? @cols_count.times do |col_index| col, cell_value = read_cell(@headers, col_index) yield Header.new(col: col, value: cell_value) end self end |
#each_row ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/tabulard/adapters/bare.rb', line 34 def each_row raise_if_closed return to_enum(:each_row) { @rows_count } unless block_given? @rows_count.times do |row_index| row, row_data = read_row(row_index) row_value = Array.new(@cols_count) do |col_index| col, cell_value = read_cell(row_data, col_index) Cell.new(row: row, col: col, value: cell_value) end yield Row.new(row: row, value: row_value) end self end |