Sha256: eac9b09459bdf6ba5c2fe071fe97b70747b646ea12a8440c4bb99e16ac398c7d

Contents?: true

Size: 815 Bytes

Versions: 3

Compression:

Stored size: 815 Bytes

Contents

require 'xmlss/element/column'
require 'xmlss/element/row'
require 'xmlss/element/cell'

module Xmlss; end
module Xmlss::Element
  class Worksheet

    def self.writer; :worksheet; end

    attr_accessor :name

    def initialize(*args)
      attrs, self.name = [
        args.last.kind_of?(::Hash) ? args.pop : {},
        args.last
      ]
    end

    def name=(value)
      if value.to_s.length > 31
        raise ArgumentError, "worksheet names must be less than 32 characters long"
      end
      @name = if !value.nil? && !value.to_s.empty?
        sanitized_name(value.to_s)
      else
        ""
      end
    end

    private

    def sanitized_name(name)
      # worksheet name cannot contain: /, \, :, ;, * or start with '['
      name.to_s.gsub(/[\/|\\|:|;|\*]/, '').gsub(/^\[/, '')
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
xmlss-1.0.0.rc.4 lib/xmlss/element/worksheet.rb
xmlss-1.0.0.rc.3 lib/xmlss/element/worksheet.rb
xmlss-1.0.0.rc.2 lib/xmlss/element/worksheet.rb