class DocxTools::PartList
Attributes
parts[RW]
the stored list of parts
Public Class Methods
new(document, content_types)
click to toggle source
parse the content type entries out of the given document
# File lib/docx_tools/part_list.rb, line 8 def initialize(document, content_types) self.parts = {} content_types.map!(&method(:expand_type)) document.get('[Content_Types].xml').xpath(content_types.join(' | ')).each do |tag| filename = tag['PartName'].split('/', 2)[1] parts[filename] = document.get(filename) end end
Public Instance Methods
each_part(&block)
click to toggle source
yield each part to the block
# File lib/docx_tools/part_list.rb, line 19 def each_part(&block) parts.values.each(&block) end
get(filename)
click to toggle source
get the requested part
# File lib/docx_tools/part_list.rb, line 24 def get(filename) parts[filename] end
has?(filename)
click to toggle source
true if this part list has extracted this part from the document
# File lib/docx_tools/part_list.rb, line 29 def has?(filename) parts.key?(filename) end
Private Instance Methods
expand_type(content_type)
click to toggle source
# File lib/docx_tools/part_list.rb, line 35 def expand_type(content_type) "xmlns:Types/xmlns:Override[@ContentType='application/vnd.openxmlformats-officedocument.wordprocessingml.#{content_type}+xml']" end