Class: OoxmlParser::DocumentProperties

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

Overview

Document Properties

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Instance Method Summary collapse

Methods inherited from OOXMLDocumentObject

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

Methods included from OoxmlObjectAttributeHelper

#attribute_enabled?, #option_enabled?

Methods included from OoxmlDocumentObjectHelper

#to_hash

Constructor Details

This class inherits a constructor from OoxmlParser::OOXMLDocumentObject

Instance Attribute Details

#pagesObject

Returns the value of attribute pages.



6
7
8
# File 'lib/ooxml_parser/docx_parser/document_structure/document_properties.rb', line 6

def pages
  @pages
end

#wordsObject

Returns the value of attribute words.



6
7
8
# File 'lib/ooxml_parser/docx_parser/document_structure/document_properties.rb', line 6

def words
  @words
end

Instance Method Details

#parseDocumentProperties

Parse Document properties

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/ooxml_parser/docx_parser/document_structure/document_properties.rb', line 10

def parse
  properties_file = "#{root_object.unpacked_folder}docProps/app.xml"
  unless File.exist?(properties_file)
    warn "There is no 'docProps/app.xml' in docx. It may be some problem with it"
    return self
  end
  node = parse_xml(properties_file)
  node.xpath('*').each do |node_child|
    case node_child.name
    when 'Properties'
      node_child.xpath('*').each do |node_child_child|
        case node_child_child.name
        when 'Pages'
          @pages = node_child_child.text.to_i
        when 'Words'
          @words = node_child_child.text.to_i
        end
      end
    end
  end
  self
end