Class: Saxlsx::StyleCollectionParser

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ StyleCollectionParser



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

def initialize(&block)
  @block = block
  @cell_styles = false
  @custom_num_fmts = {}
end

Class Method Details

.parse(file_system, &block) ⇒ Object



3
4
5
# File 'lib/saxlsx/style_collection_parser.rb', line 3

def self.parse(file_system, &block)
  SaxParser.parse self.new(&block), file_system.styles
end

Instance Method Details

#attr(name, value) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/saxlsx/style_collection_parser.rb', line 43

def attr(name, value)
  case name
  when :numFmtId
    @num_fmt_id = value.to_i
  when :formatCode
    @num_fmt_code = value
  end
end

#end_element(name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/saxlsx/style_collection_parser.rb', line 25

def end_element(name)
  case name
  when :cellXfs
    @cell_styles = false
  when :xf
    if @cell_styles
      custom_num_fmt_code = @custom_num_fmts[@num_fmt_id]
      if custom_num_fmt_code
        @block.call custom_num_fmt_code
      else
        @block.call @num_fmt_id
      end
    end
  when :numFmt
    @custom_num_fmts[@num_fmt_id] = @num_fmt_code
  end
end

#start_element(name) ⇒ Object



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

def start_element(name)
  case name
  when :cellXfs
    @cell_styles = true
  when :xf
    @num_fmt_id = nil
  when :numFmt
    @num_fmt_id = nil
    @num_fmt_code = nil
  end
end