class Osheet::Xmlss::StyleCache
Attributes
styles[R]
Public Class Methods
new(osheet_workbook, xmlss_workbook)
click to toggle source
# 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
Public Instance Methods
[](key)
click to toggle source
# File lib/osheet/xmlss/style_cache.rb, line 15 def [](key); @styles[key]; end
empty?()
click to toggle source
# File lib/osheet/xmlss/style_cache.rb, line 16 def empty?; @styles.empty?; end
get(style_class, format)
click to toggle source
# 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)
click to toggle source
build a unique key for styling based off the style and format keys
# File lib/osheet/xmlss/style_cache.rb, line 34 def key(class_value, format_key) "#{(class_value || '').strip.gsub(/\s+/, '.')}..#{format_key}" end
keys()
click to toggle source
# File lib/osheet/xmlss/style_cache.rb, line 19 def keys @styles.keys end
size()
click to toggle source
# File lib/osheet/xmlss/style_cache.rb, line 17 def size; @styles.keys.size; end
Protected Instance Methods
build_and_cache(key, styles, format)
click to toggle source
build and cache an xmlss style
# File lib/osheet/xmlss/style_cache.rb, line 41 def build_and_cache(key, styles, format) settings = StyleSettings.new(styles) @styles[key] = @xmlss_workbook.style(key) { settings.setting(:align) { @xmlss_workbook.alignment(settings[:align]) } settings.setting(:font) { @xmlss_workbook.font(settings[:font]) } settings.setting(:bg) { @xmlss_workbook.interior(settings[:bg]) } border_set = ::Osheet::Style::BORDERS.inject([]) do |set, bp| settings.setting(bp) { set << settings[bp] } set end if !border_set.empty? @xmlss_workbook.borders { border_set.each { |setting| @xmlss_workbook.border(setting) } } end @xmlss_workbook.number_format(format.style) } end