lib/xmlss/element/worksheet.rb in xmlss-0.4.1 vs lib/xmlss/element/worksheet.rb in xmlss-1.0.0.rc.1

- old
+ new

@@ -1,24 +1,32 @@ require 'xmlss/element/column' require 'xmlss/element/row' require 'xmlss/element/cell' -require 'xmlss/element/data' module Xmlss; end module Xmlss::Element class Worksheet + def self.writer; :worksheet; end + attr_accessor :name - def initialize(name, attrs={}) - self.name = name + def initialize(*args) + attrs, self.name = [ + args.last.kind_of?(::Hash) ? args.pop : {}, + args.last + ] end def name=(value) - if value.nil? || value.to_s.empty? - raise ArgumentError, "'#{name.inspect}' is not a good name for a worksheet" + if value.to_s.length > 31 + raise ArgumentError, "worksheet names must be less than 32 characters long" end - @name = sanitized_name(value.to_s) + @name = if !value.nil? && !value.to_s.empty? + sanitized_name(value.to_s) + else + "" # TODO: make sure you don't write a worksheet with no sanitized_name + end end private def sanitized_name(name)