lib/osheet/workbook.rb in osheet-0.4.0 vs lib/osheet/workbook.rb in osheet-0.5.0

- old
+ new

@@ -1,36 +1,47 @@ +require 'osheet/instance' require 'osheet/style_set' require 'osheet/template_set' require 'osheet/worksheet' require 'osheet/xmlss_writer' module Osheet class Workbook + include Instance include Associations hm :worksheets - attr_reader :styles, :templates def initialize(&block) - @title = nil - @styles = StyleSet.new - @templates = TemplateSet.new - instance_eval(&block) if block_given? + set_ivar(:title, nil) + set_ivar(:styles, StyleSet.new) + set_ivar(:templates, TemplateSet.new) + if block_given? + set_binding_ivars(block.binding) + instance_eval(&block) + end end def title(value=nil) - !value.nil? ? @title = value : @title + !value.nil? ? set_ivar(:title, value) : get_ivar(:title) end - def style(*selectors, &block); @styles << Style.new(*selectors, &block); end - def template(element, name, &block); @templates << Template.new(element, name, &block); end + def style(*selectors, &block); push_ivar(:styles, Style.new(*selectors, &block)); end + def styles + get_ivar(:styles) + end + def template(element, name, &block); push_ivar(:templates, Template.new(element, name, &block)); end + def templates + get_ivar(:templates) + end + def attributes - { :title => @title } + { :title => get_ivar(:title) } end def use(mixin) - (mixin.styles || []).each{ |s| @styles << s } - (mixin.templates || []).each{ |t| @templates << t } + (mixin.styles || []).each{ |s| push_ivar(:styles, s) } + (mixin.templates || []).each{ |t| push_ivar(:templates, t) } end def writer XmlssWriter::Base.new(:workbook => self) end