Sha256: 64e83da45a3d7faaea4b6fd2c8b20f068bd18123f496b99646f0b43a7fb1f302
Contents?: true
Size: 1.08 KB
Versions: 7
Compression:
Stored size: 1.08 KB
Contents
require 'osheet/column' require 'osheet/row' module Osheet class Worksheet include Instance include Associations include WorkbookElement include MetaElement include MarkupElement hm :columns hm :rows def initialize(workbook=nil, *args, &block) set_ivar(:workbook, workbook) set_ivar(:name, nil) if block_given? set_binding_ivars(block.binding) instance_exec(*args, &block) end end def name(value=nil) !value.nil? ? set_ivar(:name, sanitized_name(value)) : get_ivar(:name) end def attributes { :name => get_ivar(:name) } end private def sanitized_name(name_value) if get_ivar(:workbook) && get_ivar(: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 if name_value.to_s.length > 31 raise ArgumentError, "worksheet names must be less than 32 characters long" end name_value.to_s end end end
Version data entries
7 entries across 7 versions & 1 rubygems