Class: Workbook::Template

Inherits:
Object
  • Object
show all
Includes:
Modules::RawObjectsStorage
Defined in:
lib/workbook/template.rb

Overview

Workbook::Template is a container for different Workbook::Format's and the storage of raw template data that isn't really supported by Workbook, but should survive a typical read/write cyclus.

Instance Method Summary collapse

Methods included from Modules::RawObjectsStorage

#add_raw, #available_raws, #has_raw_for?, #raws, #remove_all_raws!, #return_raw_for

Constructor Details

#initializeTemplate

Initialize Workbook::Template



10
11
12
13
# File 'lib/workbook/template.rb', line 10

def initialize
  @formats = {}
  @has_header = true
end

Instance Method Details

#add_format(format) ⇒ Object

Add a Workbook::Format to the template



22
23
24
25
26
27
28
# File 'lib/workbook/template.rb', line 22

def add_format format
  if format.is_a? Workbook::Format
    @formats[format.name]=format
  else
    raise ArgumentError, "format should be a Workboot::Format"
  end
end

#create_or_find_format_by(name, variant = :default) ⇒ Workbook::Format

Create or find a format by name



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/workbook/template.rb', line 40

def create_or_find_format_by name, variant=:default
  fs = @formats[name]
  fs = @formats[name] = {} if fs.nil?
  f = fs[variant]
  if f.nil?
    f = Workbook::Format.new
    if variant != :default and fs[:default]
      f = fs[:default].clone
    end
    @formats[name][variant] = f
  end
  return @formats[name][variant]
end

#formatsHash

Return the list of associated formats



32
33
34
# File 'lib/workbook/template.rb', line 32

def formats
  @formats
end

#has_header?Boolean

Whether the template has a predefined header (headers are used )



16
17
18
# File 'lib/workbook/template.rb', line 16

def has_header?
  @has_header
end