Class: Saxlsx::RowsCollectionParser

Inherits:
Ox::Sax
  • Object
show all
Defined in:
lib/saxlsx/rows_collection_parser.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(shared_strings, &block) ⇒ RowsCollectionParser

Returns a new instance of RowsCollectionParser.



8
9
10
11
# File 'lib/saxlsx/rows_collection_parser.rb', line 8

def initialize(shared_strings, &block)
  @shared_strings = shared_strings
  @block = block
end

Class Method Details

.parse(index, file_system, shared_strings, &block) ⇒ Object



4
5
6
# File 'lib/saxlsx/rows_collection_parser.rb', line 4

def self.parse(index, file_system, shared_strings, &block)
  SaxParser.parse self.new(shared_strings, &block), file_system.sheets[index]
end

Instance Method Details

#attr(name, value) ⇒ Object



31
32
33
34
35
36
# File 'lib/saxlsx/rows_collection_parser.rb', line 31

def attr(name, value)
  if @current_element == :c
    @current_type = value if name == :t
    @current_column = value.gsub(/\d/, '') if name == :r
  end
end

#end_element(name) ⇒ Object



24
25
26
27
28
29
# File 'lib/saxlsx/rows_collection_parser.rb', line 24

def end_element(name)
  if name == :row
    @block.call @current_row
    @current_row = nil
  end
end

#start_element(name) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/saxlsx/rows_collection_parser.rb', line 13

def start_element(name)
  @current_element = name

  if name == :row
    @current_row = []
    @next_column = 'A'
  end

  @current_type = nil if name == :c
end

#text(value) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/saxlsx/rows_collection_parser.rb', line 38

def text(value)
  if @current_row && @current_element == :v
    while @next_column != @current_column
      @current_row << nil
      @next_column = ColumnNameGenerator.next_to(@next_column)
    end
    @current_row << value_of(value)
    @next_column = ColumnNameGenerator.next_to(@next_column)
  end
end