Class: Osheet::Xmlss::StyleCache

Inherits:
Object
  • Object
show all
Defined in:
lib/osheet/xmlss/style_cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(osheet_workbook, xmlss_workbook) ⇒ StyleCache

Returns a new instance of StyleCache.



9
10
11
12
13
# File 'lib/osheet/xmlss/style_cache.rb', line 9

def initialize(osheet_workbook, xmlss_workbook)
  @osheet_workbook = osheet_workbook
  @xmlss_workbook  = xmlss_workbook
  @styles = {}
end

Instance Attribute Details

#stylesObject (readonly)

Returns the value of attribute styles.



7
8
9
# File 'lib/osheet/xmlss/style_cache.rb', line 7

def styles
  @styles
end

Instance Method Details

#[](key) ⇒ Object



15
# File 'lib/osheet/xmlss/style_cache.rb', line 15

def [](key); @styles[key];      end

#empty?Boolean

Returns:

  • (Boolean)


16
# File 'lib/osheet/xmlss/style_cache.rb', line 16

def empty?;  @styles.empty?;    end

#get(style_class, format) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/osheet/xmlss/style_cache.rb', line 23

def get(style_class, format)
  # generate the style key and get the get the cached style or
  # build and cache and return a style for the key
  key = self.key(style_class, format.key)
  return nil if key == '..'

  @styles[key] ||
  build_and_cache(key, @osheet_workbook.styles.for(style_class), format)
end

#key(class_value, format_key) ⇒ Object

build a unique key for styling based off the style and format keys



34
35
36
# File 'lib/osheet/xmlss/style_cache.rb', line 34

def key(class_value, format_key)
  "#{(class_value || '').strip.gsub(/\s+/, '.')}..#{format_key}"
end

#keysObject



19
20
21
# File 'lib/osheet/xmlss/style_cache.rb', line 19

def keys
  @styles.keys
end

#sizeObject



17
# File 'lib/osheet/xmlss/style_cache.rb', line 17

def size;    @styles.keys.size; end