lib/osheet/worksheet.rb in osheet-0.2.0 vs lib/osheet/worksheet.rb in osheet-0.3.0

- old
+ new

@@ -14,14 +14,23 @@ @name = nil instance_exec(*args, &block) if block_given? end def name(value=nil) - !value.nil? ? @name = value : @name + !value.nil? ? @name = sanitized_name(value) : @name end def attributes { :name => @name } + end + + private + + def sanitized_name(name_value) + if @workbook && @workbook.worksheets.collect{|ws| ws.name}.include?(name_value) + raise ArgumentError, "the sheet name '#{name_value}' is already in use. choose a sheet name that is not used by another sheet" + end + name_value end end end