Class: SpreadsheetStreamReader::Reader
- Inherits:
-
Object
- Object
- SpreadsheetStreamReader::Reader
- Defined in:
- lib/spreadsheet_stream_reader.rb
Constant Summary collapse
- VALID_FILE_EXTS =
%w(.xls)
Instance Attribute Summary collapse
-
#batch_size ⇒ Object
Returns the value of attribute batch_size.
-
#data ⇒ Object
Returns the value of attribute data.
-
#file_path ⇒ Object
Returns the value of attribute file_path.
Instance Method Summary collapse
- #each_sheet ⇒ Object
- #get_sheet(idx_or_name) ⇒ Object
-
#initialize(file_path, batch_size = 1000) ⇒ Reader
constructor
A new instance of Reader.
- #sheet_names ⇒ Object
Constructor Details
#initialize(file_path, batch_size = 1000) ⇒ Reader
Returns a new instance of Reader.
13 14 15 16 17 18 19 20 |
# File 'lib/spreadsheet_stream_reader.rb', line 13 def initialize(file_path, batch_size = 1000) raise InvalidParameterError, "File extension should be one of the: #{VALID_FILE_EXTS}" unless VALID_FILE_EXTS.include?(File.extname(file_path.to_s)) self.file_path = file_path.to_s self.batch_size = batch_size self.data = Array.new end |
Instance Attribute Details
#batch_size ⇒ Object
Returns the value of attribute batch_size.
9 10 11 |
# File 'lib/spreadsheet_stream_reader.rb', line 9 def batch_size @batch_size end |
#data ⇒ Object
Returns the value of attribute data.
9 10 11 |
# File 'lib/spreadsheet_stream_reader.rb', line 9 def data @data end |
#file_path ⇒ Object
Returns the value of attribute file_path.
9 10 11 |
# File 'lib/spreadsheet_stream_reader.rb', line 9 def file_path @file_path end |
Instance Method Details
#each_sheet ⇒ Object
30 31 32 33 34 |
# File 'lib/spreadsheet_stream_reader.rb', line 30 def each_sheet sheet_names.each do |name| yield get_sheet(name) end end |
#get_sheet(idx_or_name) ⇒ Object
26 27 28 |
# File 'lib/spreadsheet_stream_reader.rb', line 26 def get_sheet(idx_or_name) Sheet.new(book_reader.get_work_sheet(idx_or_name), @batch_size) end |
#sheet_names ⇒ Object
22 23 24 |
# File 'lib/spreadsheet_stream_reader.rb', line 22 def sheet_names sheets.collect{|s| s.name} end |