Class: OoxmlParser::TableStyles

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/pptx_parser/presentation/table_styles.rb

Overview

Class for parsing ‘tableStyles.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) ⇒ TableStyles

Returns a new instance of TableStyles.



9
10
11
12
# File 'lib/ooxml_parser/pptx_parser/presentation/table_styles.rb', line 9

def initialize(parent: nil)
  @table_style_list = []
  super
end

Instance Attribute Details

#table_style_listArray<TableStyle> (readonly)

Returns list of table styles.

Returns:



7
8
9
# File 'lib/ooxml_parser/pptx_parser/presentation/table_styles.rb', line 7

def table_style_list
  @table_style_list
end

Instance Method Details

#parse(file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/tableStyles.xml") ⇒ TableStyles

Parse TableStyles object

Parameters:

  • file (Nokogiri::XML:Element) (defaults to: "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/tableStyles.xml")

    node to parse

Returns:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ooxml_parser/pptx_parser/presentation/table_styles.rb', line 17

def parse(file = "#{root_object.unpacked_folder}/#{root_object.root_subfolder}/tableStyles.xml")
  return nil unless File.exist?(file)

  document = parse_xml(file)
  node = document.xpath('*').first

  node.xpath('*').each do |node_child|
    case node_child.name
    when 'tblStyle'
      @table_style_list << TableStyle.new(parent: self).parse(node_child)
    end
  end
  self
end

#style_by_id(id) ⇒ TableStyle

Returns style by this id.

Parameters:

  • id (String)

    style to find

Returns:



34
35
36
# File 'lib/ooxml_parser/pptx_parser/presentation/table_styles.rb', line 34

def style_by_id(id)
  table_style_list.detect { |style| style.id == id }
end