Module: Workbook::Modules::RawObjectsStorage

Included in:
Format, Template
Defined in:
lib/workbook/modules/raw_objects_storage.rb

Overview

Adds support for storing raw objects, used in e.g. Format and Template

Instance Method Summary collapse

Instance Method Details

#add_raw(raw_object, options = {}) ⇒ Object

A raw is a ‘raw’ object, representing a workbook, or cell, or whatever… in a particular format (defined by its class)



11
12
13
14
# File 'lib/workbook/modules/raw_objects_storage.rb', line 11

def add_raw raw_object, options={}
  class_of_obj = options[:raw_object_class] ? options[:raw_object_class] : raw_object.class
  raws[class_of_obj]=raw_object
end

#available_rawsArray<Object>

Lists the classes for which raws are available

Returns:

  • (Array<Object>)

    array with the classes available



35
36
37
# File 'lib/workbook/modules/raw_objects_storage.rb', line 35

def available_raws
  raws.keys
end

#has_raw_for?(raw_object_class) ⇒ Boolean

Returns true if there is a template for a certain class, otherwise false

Returns:

  • (Boolean)


17
18
19
# File 'lib/workbook/modules/raw_objects_storage.rb', line 17

def has_raw_for? raw_object_class
  available_raws.include? raw_object_class
end

#rawsObject

Return all raw data references



40
41
42
43
# File 'lib/workbook/modules/raw_objects_storage.rb', line 40

def raws
  @raws = {} unless defined? @raws
  @raws
end

#remove_all_raws!Object

Remove all raw data references



29
30
31
# File 'lib/workbook/modules/raw_objects_storage.rb', line 29

def remove_all_raws!
  @raws = {}
end

#return_raw_for(raw_object_class) ⇒ Object

Returns raw data stored for a type of raw object (if available)

Parameters:

  • raw_object_class (Class)

    (e.g. Spreadsheet::Format for the Spreadsheet-gem)



23
24
25
26
# File 'lib/workbook/modules/raw_objects_storage.rb', line 23

def return_raw_for raw_object_class
  raws.each { |tc,t| return t if tc == raw_object_class}
  return nil
end