Class: Writexlsx::Worksheet::CellDataStore
- Inherits:
-
Object
- Object
- Writexlsx::Worksheet::CellDataStore
- Defined in:
- lib/write_xlsx/worksheet/cell_data_store.rb
Overview
:nodoc:
Instance Method Summary collapse
- #[](row) ⇒ Object
- #each_row ⇒ Object
- #fetch(row, col) ⇒ Object
- #get_range_data(row_start, col_start, row_end, col_end) ⇒ Object
-
#initialize ⇒ CellDataStore
constructor
A new instance of CellDataStore.
- #row(row) ⇒ Object
- #row?(row) ⇒ Boolean
- #store(cell_data, row, col) ⇒ Object
Constructor Details
#initialize ⇒ CellDataStore
Returns a new instance of CellDataStore.
7 8 9 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 7 def initialize @table = [] end |
Instance Method Details
#[](row) ⇒ Object
11 12 13 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 11 def [](row) @table[row] end |
#each_row ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 52 def each_row return enum_for(__method__) unless block_given? @table.each_with_index do |row_data, row_num| yield row_num, row_data if row_data end end |
#fetch(row, col) ⇒ Object
28 29 30 31 32 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 28 def fetch(row, col) return nil unless @table[row] @table[row][col] end |
#get_range_data(row_start, col_start, row_end, col_end) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 34 def get_range_data(row_start, col_start, row_end, col_end) data = [] (row_start..row_end).each do |row_num| unless row?(row_num) data << nil next end (col_start..col_end).each do |col_num| cell = fetch(row_num, col_num) data << (cell ? cell.data : nil) end end data end |
#row(row) ⇒ Object
15 16 17 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 15 def row(row) @table[row] end |
#row?(row) ⇒ Boolean
19 20 21 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 19 def row?(row) !@table[row].nil? end |
#store(cell_data, row, col) ⇒ Object
23 24 25 26 |
# File 'lib/write_xlsx/worksheet/cell_data_store.rb', line 23 def store(cell_data, row, col) @table[row] ||= [] @table[row][col] = cell_data end |