class Saxlsx::StyleCollectionParser

Public Class Methods

new(&block) click to toggle source
# File lib/saxlsx/style_collection_parser.rb, line 8
def initialize(&block)
  @block = block
  @cell_styles = false
  @custom_num_fmts = {}
end
parse(file_system, &block) click to toggle source
# File lib/saxlsx/style_collection_parser.rb, line 4
def self.parse(file_system, &block)
  SaxParser.parse self.new(&block), file_system.styles
end

Public Instance Methods

attr(name, value) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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