Class: Saxlsx::SharedStringCollectionParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ SharedStringCollectionParser

Returns a new instance of SharedStringCollectionParser.



13
14
15
# File 'lib/saxlsx/shared_string_collection_parser.rb', line 13

def initialize(&block)
  @block = block
end

Class Method Details

.parse(file_system, &block) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/saxlsx/shared_string_collection_parser.rb', line 4

def self.parse(file_system, &block)
  shared_strings = file_system.shared_strings
  if shared_strings
    SaxParser.parse self.new(&block), shared_strings
  else
    []
  end
end

Instance Method Details

#end_element(name) ⇒ Object



21
22
23
24
25
26
# File 'lib/saxlsx/shared_string_collection_parser.rb', line 21

def end_element(name)
  if name == :si
    @block.call @current_string
    @current_string = nil
  end
end

#start_element(name) ⇒ Object



17
18
19
# File 'lib/saxlsx/shared_string_collection_parser.rb', line 17

def start_element(name)
  @current_string = '' if name == :si
end

#text(value) ⇒ Object



28
29
30
# File 'lib/saxlsx/shared_string_collection_parser.rb', line 28

def text(value)
  @current_string << CGI.unescapeHTML(value) if @current_string
end