Class: Docx::Elements::Containers::StylesConfiguration
- Inherits:
-
Object
- Object
- Docx::Elements::Containers::StylesConfiguration
- Defined in:
- lib/docx/containers/styles_configuration.rb
Instance Attribute Summary collapse
-
#styles ⇒ Object
readonly
Returns the value of attribute styles.
-
#styles_parent_node ⇒ Object
readonly
Returns the value of attribute styles_parent_node.
Instance Method Summary collapse
- #add_style(id, attributes = {}) ⇒ Object
-
#initialize(raw_styles) ⇒ StylesConfiguration
constructor
A new instance of StylesConfiguration.
- #remove_style(id) ⇒ Object
- #serialize(**options) ⇒ Object
- #size ⇒ Object
- #style_of(id_or_name) ⇒ Object
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
#styles ⇒ Object (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_node ⇒ Object (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(**) @raw_styles.serialize(**) end |
#size ⇒ Object
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 |