Class: Ruby2xlsx::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby2xlsx/base.rb

Direct Known Subclasses

Document, Template

Instance Method Summary collapse

Constructor Details

#initialize(source, options = {}) ⇒ Base

Constructs a new ejs engine based on given xlsx“, :root => true, :view_path => ”/path/to/views“ })



8
9
10
11
12
13
# File 'lib/ruby2xlsx/base.rb', line 8

def initialize(source, options = {})
  @source = source
  @options = options
  @compiled = false
  @io = ::StringIO.new
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/ruby2xlsx/base.rb', line 36

def method_missing(m, *args, &block)
  if worksheet.respond_to?(m)
    worksheet.send(m, *args, &block)
  elsif workbook.respond_to?(m)
    workbook.send(m, *args, &block)
  else
    super
  end
end

Instance Method Details

#add_worksheet(*args) ⇒ Object



23
24
25
# File 'lib/ruby2xlsx/base.rb', line 23

def add_worksheet(*args)
  @worksheet = workbook.add_worksheet(*args)
end

#render(*args) ⇒ Object



27
28
29
30
# File 'lib/ruby2xlsx/base.rb', line 27

def render(*args)
  workbook.close
  @io.string
end

#workbookObject



15
16
17
# File 'lib/ruby2xlsx/base.rb', line 15

def workbook
  @workbook ||= ::WriteExcel.new(@io)
end

#worksheetObject



19
20
21
# File 'lib/ruby2xlsx/base.rb', line 19

def worksheet
  @worksheet ||= add_worksheet(worksheet_name)
end

#worksheet_nameObject



32
33
34
# File 'lib/ruby2xlsx/base.rb', line 32

def worksheet_name
  "somename"
end