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

Returns a new instance of StyleCollectionParser.



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

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

Class Method Details

.parse(file_system, &block) ⇒ Object



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

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

Instance Method Details

#attr(name, value) ⇒ Object



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

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



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

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.to_i
      end
    end
  when :numFmt
    @custom_num_fmts[@num_fmt_id] = @num_fmt_code
  end
end

#start_element(name) ⇒ Object



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

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