Sha256: dad15a8a77bd9863ef588a86daa803d0ac1154a607f5f259c039983ffbc2f7da

Contents?: true

Size: 714 Bytes

Versions: 4

Compression:

Stored size: 714 Bytes

Contents

# frozen_string_literal: true
module Saxlsx
  class RowsCollectionCountParser < Ox::Sax
    def self.count(data, &block)
      parser = new
      catch :abort do
        SaxParser.parse parser, data
      end
      parser.count
    end

    attr_reader :count

    def initialize
      @count = 0
    end

    def start_element(name)
      @current_element = name
      if name == :row
        @count += 1
      end
    end

    def attr(name, value)
      if @current_element == :dimension
        if name == :ref && value
          matches = value.match(/[^:]+:[A-Z]*(\d+)/)
          if matches
            @count = matches[1].to_i
            throw :abort
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
saxlsx-1.11.0 lib/saxlsx/rows_collection_count_parser.rb
saxlsx-1.10.0 lib/saxlsx/rows_collection_count_parser.rb
saxlsx-1.9.0 lib/saxlsx/rows_collection_count_parser.rb
saxlsx-1.8.0 lib/saxlsx/rows_collection_count_parser.rb