Class: Workbook::Template
- Inherits:
-
Object
- Object
- Workbook::Template
- 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
-
#add_format(format) ⇒ Object
Add a Workbook::Format to the template.
-
#create_or_find_format_by(name, variant = :default) ⇒ Workbook::Format
Create or find a format by name.
-
#formats ⇒ Hash
Return the list of associated formats.
-
#has_header? ⇒ Boolean
Whether the template has a predefined header (headers are used ).
-
#initialize ⇒ Template
constructor
Initialize Workbook::Template.
- #set_default_formats! ⇒ Object
Methods included from Modules::RawObjectsStorage
#add_raw, #available_raws, #has_raw_for?, #raws, #remove_all_raws!, #return_raw_for
Constructor Details
#initialize ⇒ Template
Initialize Workbook::Template
13 14 15 16 |
# File 'lib/workbook/template.rb', line 13 def initialize @formats = {} @has_header = true end |
Instance Method Details
#add_format(format) ⇒ Object
Add a Workbook::Format to the template
25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Workbook::Format
Create or find a format by name
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 ⇒ Hash
Return the list of associated formats
39 40 41 |
# File 'lib/workbook/template.rb', line 39 def formats @formats end |
#has_header? ⇒ Boolean
Whether the template has a predefined header (headers are used )
19 20 21 |
# File 'lib/workbook/template.rb', line 19 def has_header? @has_header end |
#set_default_formats! ⇒ Object
61 62 63 64 |
# 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 |