Class: BerkeleyLibrary::Util::ODS::XML::Style::CellStyle

Inherits:
Style show all
Defined in:
lib/berkeley_library/util/ods/xml/style/cell_style.rb

Instance Attribute Summary collapse

Attributes inherited from Style

#family, #style_name

Attributes inherited from ElementNode

#doc, #element_name, #namespace

Instance Method Summary collapse

Methods inherited from Style

#<=>

Methods inherited from ElementNode

#add_child, #attributes, #children, #clear_attribute, #create_element, #element, #ensure_element!, #prefix, #prefixed_attr_name, #set_attribute

Constructor Details

#initialize(name, protected = false, color = nil, styles:, font_weight: nil, wrap: false) ⇒ CellStyle

Initializes a new cell style. Note that this should not be called directly, but only from Office::AutomaticStyles#add_cell_style.

rubocop:disable Metrics/ParameterLists, Style/OptionalBooleanParameter

Parameters:

  • name (String)

    the style name

  • color (String, nil) (defaults to: nil)

    a hex color (e.g. #fdb515)

  • font_weight (String, nil) (defaults to: nil)

    the font weight, if other than normal

  • wrap (Boolean) (defaults to: false)

    whether to allow text wrapping

  • styles (XML::Office::AutomaticStyles)

    the document styles



23
24
25
26
27
28
29
30
31
32
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 23

def initialize(name, protected = false, color = nil, styles:, font_weight: nil, wrap: false)
  super(name, :table_cell, doc: styles.doc)
  @protected = protected
  @color = color
  @font_weight = font_weight
  @wrap = wrap

  set_attribute('parent-style-name', 'Default')
  add_default_children!
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



12
13
14
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 12

def color
  @color
end

#font_weightObject (readonly)

Returns the value of attribute font_weight.



12
13
14
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 12

def font_weight
  @font_weight
end

Instance Method Details

#custom_text_properties?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 43

def custom_text_properties?
  [color, font_weight].any? { |p| !p.nil? }
end

#protected?Boolean

rubocop:enable Metrics/ParameterLists, Style/OptionalBooleanParameter

Returns:

  • (Boolean)


35
36
37
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 35

def protected?
  @protected
end

#wrap?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/berkeley_library/util/ods/xml/style/cell_style.rb', line 39

def wrap?
  @wrap
end