Class: OoxmlParser::Styles
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Styles
- Defined in:
- lib/ooxml_parser/docx_parser/document_structure/styles.rb
Overview
Class for parsing ‘styles.xml` file
Instance Attribute Summary collapse
-
#document_defaults ⇒ DocumentDefaults
Defaults of document.
-
#styles ⇒ Array<DocumentStyle>
readonly
Array of document styles.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#default_style(type) ⇒ DocumentStyle
Default document style.
-
#initialize(parent: nil) ⇒ Styles
constructor
A new instance of Styles.
-
#parse ⇒ Styles
Parse styles data.
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml, #with_data?
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ Styles
Returns a new instance of Styles.
12 13 14 15 |
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 12 def initialize(parent: nil) @styles = [] super end |
Instance Attribute Details
#document_defaults ⇒ DocumentDefaults
Returns defaults of document.
8 9 10 |
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 8 def document_defaults @document_defaults end |
#styles ⇒ Array<DocumentStyle> (readonly)
Returns array of document styles.
10 11 12 |
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 10 def styles @styles end |
Instance Method Details
#default_style(type) ⇒ DocumentStyle
Returns default document style.
34 35 36 |
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 34 def default_style(type) styles.find { |style| style.type == type && style.default } end |
#parse ⇒ Styles
Parse styles data
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 19 def parse doc = parse_xml("#{root_object.unpacked_folder}word/styles.xml") doc.xpath('w:styles/*').each do |node_child| case node_child.name when 'docDefaults' @document_defaults = DocumentDefaults.new(parent: self).parse(node_child) when 'style' @styles << DocumentStyle.new(parent: self).parse(node_child) end end self end |