Class: SpreadsheetStreamReader::Reader

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_stream_reader.rb

Constant Summary collapse

VALID_FILE_EXTS =
%w(.xls)

Instance Attribute Summary collapse

Instance Method Summary collapse

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_sizeObject

Returns the value of attribute batch_size.



9
10
11
# File 'lib/spreadsheet_stream_reader.rb', line 9

def batch_size
  @batch_size
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/spreadsheet_stream_reader.rb', line 9

def data
  @data
end

#file_pathObject

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_sheetObject



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_namesObject



22
23
24
# File 'lib/spreadsheet_stream_reader.rb', line 22

def sheet_names
  sheets.collect{|s| s.name}
end