Class: Osheet::Xmlss::StyleCache
- Inherits:
-
Object
- Object
- Osheet::Xmlss::StyleCache
- Defined in:
- lib/osheet/xmlss/style_cache.rb
Instance Attribute Summary collapse
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #empty? ⇒ Boolean
- #get(style_class, format) ⇒ Object
-
#initialize(osheet_workbook, xmlss_workbook) ⇒ StyleCache
constructor
A new instance of StyleCache.
-
#key(class_value, format_key) ⇒ Object
build a unique key for styling based off the style and format keys.
- #keys ⇒ Object
- #size ⇒ Object
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
#styles ⇒ Object (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
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 |
#keys ⇒ Object
19 20 21 |
# File 'lib/osheet/xmlss/style_cache.rb', line 19 def keys @styles.keys end |
#size ⇒ Object
17 |
# File 'lib/osheet/xmlss/style_cache.rb', line 17 def size; @styles.keys.size; end |