Class: OoxmlParser::Styles

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/docx_parser/document_structure/styles.rb

Overview

Class for parsing ‘styles.xml` file

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

#==, #boolean_attribute_value, #parse_xml, #with_data?

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

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_defaultsDocumentDefaults

Returns defaults of document.

Returns:



8
9
10
# File 'lib/ooxml_parser/docx_parser/document_structure/styles.rb', line 8

def document_defaults
  @document_defaults
end

#stylesArray<DocumentStyle> (readonly)

Returns array of document styles.

Returns:



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.

Parameters:

  • type (Symbol)

    of style to get

Returns:



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

#parseStyles

Parse styles data

Returns:

  • (Styles)

    result of parsing



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