Class: SpreadsheetStreamReader::Sheet
- Inherits:
-
Object
- Object
- SpreadsheetStreamReader::Sheet
- Defined in:
- lib/spreadsheet_stream_reader/sheet.rb
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#counter ⇒ Object
Returns the value of attribute counter.
-
#data ⇒ Object
Returns the value of attribute data.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#w_sheet ⇒ Object
Returns the value of attribute w_sheet.
Instance Method Summary collapse
- #get_content_in_chunks ⇒ Object
-
#initialize(_sheet, batch_size = 1000) ⇒ Sheet
constructor
A new instance of Sheet.
- #stream_rows_in_batch ⇒ Object
Constructor Details
#initialize(_sheet, batch_size = 1000) ⇒ Sheet
Returns a new instance of Sheet.
6 7 8 9 10 11 12 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 6 def initialize(_sheet, batch_size = 1000) self.batch_size = batch_size self.offset = 1 self.counter = 0 self.data = Array.new self.w_sheet = _sheet end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
4 5 6 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 4 def batch_size @batch_size end |
#counter ⇒ Object
Returns the value of attribute counter.
4 5 6 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 4 def counter @counter end |
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 4 def data @data end |
#offset ⇒ Object
Returns the value of attribute offset.
4 5 6 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 4 def offset @offset end |
#w_sheet ⇒ Object
Returns the value of attribute w_sheet.
4 5 6 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 4 def w_sheet @w_sheet end |
Instance Method Details
#get_content_in_chunks ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 32 def get_content_in_chunks clear_data sheet.each @offset do |row| increment_counter @data << row[0..(row.size - 1)] break if reached_batch_size? || reached_end_of_file? end end |
#stream_rows_in_batch ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/spreadsheet_stream_reader/sheet.rb', line 14 def stream_rows_in_batch if block_given? while offset < max_record get_content_in_chunks @data.each do |row| yield row end increment_offset end else get_content_in_chunks increment_offset @data end end |