Class: Saxlsx::RowsCollection

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/saxlsx/rows_collection.rb

Instance Method Summary collapse

Constructor Details

#initialize(index, file_system, workbook) ⇒ RowsCollection

Returns a new instance of RowsCollection.



7
8
9
10
11
12
# File 'lib/saxlsx/rows_collection.rb', line 7

def initialize(index, file_system, workbook)
  @index = index
  @file_system = file_system
  @workbook = workbook
  @sheet = file_system.sheet(index)
end

Instance Method Details

#[](value) ⇒ Object



38
39
40
# File 'lib/saxlsx/rows_collection.rb', line 38

def [](value)
  to_a[value]
end

#countObject Also known as: size



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/saxlsx/rows_collection.rb', line 18

def count
  unless defined?(@count)
    @count = 0
    begin
      @sheet.each_line('>') do |line|
        matches = line.match(/<dimension ref="[^:]+:[A-Z]*(\d+)"/)
        if matches
          @count = matches[1].to_i
          break if @count
        end
      end
    ensure
      @sheet.rewind
    end
  end
  @count
end

#each(&block) ⇒ Object



14
15
16
# File 'lib/saxlsx/rows_collection.rb', line 14

def each(&block)
  RowsCollectionParser.parse @index, @sheet, @workbook, &block
end