Method: Osheet::Workbook#initialize

Defined in:
lib/osheet/workbook.rb

#initialize(writer = nil, data = {}, &build) ⇒ Workbook

Returns a new instance of Workbook.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/osheet/workbook.rb', line 18

def initialize(writer=nil, data={}, &build)
  # apply :data options to workbook scope
  data ||= {}
  if (data.keys.map(&:to_s) & self.public_methods.map(&:to_s)).size > 0
    raise ArgumentError, "data conflicts with workbook public methods."
  end
  metaclass = class << self; self; end
  data.each {|key, value| metaclass.class_eval { define_method(key){value} }}

  # setup the writer, element stack, and workbook_element
  writer.bind(self) if writer
  @_osheet_writer = writer
  @_osheet_element_stack = Workbook::ElementStack.new
  @_osheet_workbook_element = WorkbookElement.new

  # push the workbook element onto the element stack
  element_stack.push(workbook)

  # run any instance workbook build given
  instance_eval(&build) if build
end