Class: Workbook::Template

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

Instance Method Summary (collapse)

Methods included from Modules::RawObjectsStorage

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

Constructor Details

- (Template) initialize

Returns a new instance of Template



7
8
9
10
# File 'lib/workbook/template.rb', line 7

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

Instance Method Details

- (Object) add_format(format)



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

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

- (Object) create_or_find_format_by(name, variant = :default)



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/workbook/template.rb', line 36

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

- (Object) formats



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

def formats
  @formats
end

- (Object) has_header=(boolean)



16
17
18
19
20
21
22
# File 'lib/workbook/template.rb', line 16

def has_header= boolean
  if format.is_a? TrueClass or format.is_a? FalseClass
    @has_header = boolean
  else
    raise ArgumentError, "format should be a boolean, true of false"
  end  
end

- (Boolean) has_header?

Returns:

  • (Boolean)


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

def has_header?
  @has_header
end