Sha256: 5fbd86b9e29d6419b3b4073196719423f54ae42f2b51ec52fe6c7cb6bb9c32b1

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

module Saxlsx
  class SheetCollectionParser < Ox::Sax

    CurrentSheet = Struct.new :index, :name

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

    def initialize(file_system, workbook, &block)
      @file_system = file_system
      @workbook = workbook
      @block = block
      @index = -1
      @workbook_pr = false
    end

    def start_element(name)
      case name
      when :sheet
        @current_sheet = CurrentSheet.new(@index += 1)
      when :workbookPr
        @workbook_pr = true
      end
    end

    def end_element(name)
      case name
      when :sheet
        @block.call Sheet.new(
          @current_sheet.name,
          @current_sheet.index,
          @file_system,
          @workbook
        )
        @current_sheet = nil
      when :workbookPr
        @workbook_pr = false
      end
    end

    def attr(name, value)
      if @current_sheet
        if name == :name
          @current_sheet.name = value
        end
      elsif @workbook_pr
        if name == :date1904 && value =~ /true|1/i
          @workbook.date1904 = true
        end
      end
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
saxlsx-1.6.1 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.6.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.5.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.4.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.3.1 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.3.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.2.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.1.0 lib/saxlsx/sheet_collection_parser.rb
saxlsx-1.0.0 lib/saxlsx/sheet_collection_parser.rb