Sha256: 1ea00a33d655ac00d3fefddabfc8c6a941854300ecf678e8310f8ae93b029d5f

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

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

    def initialize(&block)
      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? ? set_ivar(:title, value) : get_ivar(:title)
    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 => get_ivar(:title) }
    end

    def use(mixin)
      (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

    [:to_data, :to_file].each do |meth|
      define_method(meth) {|*args| writer.send(meth, *args) }
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
osheet-0.5.0 lib/osheet/workbook.rb