class Workbook::Template

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.

Public Class Methods

new() click to toggle source

Initialize Workbook::Template

# File lib/workbook/template.rb, line 13
def initialize
  @formats = {}
  @has_header = true
end

Public Instance Methods

add_format(format) click to toggle source

Add a Workbook::Format to the template @param [Workbook::Format] format (of a cell) to add to the template

# File lib/workbook/template.rb, line 25
def add_format format
  if format.is_a? Workbook::Format
    if format.name
      @formats[format.name]=format
    else
      @formats[@formats.keys.count]=format
    end
  else
    raise ArgumentError, "format should be a Workboot::Format"
  end
end
create_or_find_format_by(name, variant=:default) click to toggle source

Create or find a format by name @return [Workbook::Format] The new or found format @param [String] name of the format (e.g. whatever you want, in diff names such as 'destroyed', 'updated' and 'created' are being used) @param [Symbol] variant can also be a strftime formatting string (e.g. ā€œ%Y-%m-%dā€)

# File lib/workbook/template.rb, line 47
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
formats() click to toggle source

Return the list of associated formats @return [Hash] A keyed-hash of named formats

# File lib/workbook/template.rb, line 39
def formats
  @formats
end
has_header?() click to toggle source

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

# File lib/workbook/template.rb, line 19
def has_header?
  @has_header
end
set_default_formats!() click to toggle source
# File lib/workbook/template.rb, line 61
def set_default_formats!
  header_fmt = create_or_find_format_by :header
  header_fmt[:font_weight] = 'bold'
end