Class: Docx::Elements::Containers::StylesConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/docx/containers/styles_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(raw_styles) ⇒ StylesConfiguration

Returns a new instance of StylesConfiguration.



10
11
12
13
# File 'lib/docx/containers/styles_configuration.rb', line 10

def initialize(raw_styles)
  @raw_styles = raw_styles
  @styles_parent_node = raw_styles.root
end

Instance Attribute Details

#stylesObject (readonly)

Returns the value of attribute styles.



15
16
17
# File 'lib/docx/containers/styles_configuration.rb', line 15

def styles
  @styles
end

#styles_parent_nodeObject (readonly)

Returns the value of attribute styles_parent_node.



15
16
17
# File 'lib/docx/containers/styles_configuration.rb', line 15

def styles_parent_node
  @styles_parent_node
end

Instance Method Details

#add_style(id, attributes = {}) ⇒ Object



35
36
37
# File 'lib/docx/containers/styles_configuration.rb', line 35

def add_style(id, attributes = {})
  Elements::Style.create(self, {id: id, name: id}.merge(attributes))
end

#remove_style(id) ⇒ Object



39
40
41
42
43
44
# File 'lib/docx/containers/styles_configuration.rb', line 39

def remove_style(id)
  style = styles.find { |style| style.id == id }

  style.node.remove
  styles.delete(style)
end

#serialize(**options) ⇒ Object



46
47
48
# File 'lib/docx/containers/styles_configuration.rb', line 46

def serialize(**options)
  @raw_styles.serialize(**options)
end

#sizeObject



31
32
33
# File 'lib/docx/containers/styles_configuration.rb', line 31

def size
  styles.size
end

#style_of(id_or_name) ⇒ Object



27
28
29
# File 'lib/docx/containers/styles_configuration.rb', line 27

def style_of(id_or_name)
  styles.find { |style| style.id == id_or_name || style.name == id_or_name } || raise(Errors::StyleNotFound, "Style name or id '#{id_or_name}' not found")
end