Class: DocxTools::PartList

Inherits:
Object
  • Object
show all
Defined in:
lib/docx_tools/part_list.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(document, content_types) ⇒ PartList

parse the content type entries out of the given document



8
9
10
11
12
13
14
15
16
# 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

Instance Attribute Details

#partsObject

the stored list of parts



5
6
7
# File 'lib/docx_tools/part_list.rb', line 5

def parts
  @parts
end

Instance Method Details

#each_part(&block) ⇒ Object

yield each part to the block



19
20
21
# File 'lib/docx_tools/part_list.rb', line 19

def each_part(&block)
  parts.values.each(&block)
end

#get(filename) ⇒ Object

get the requested part



24
25
26
# File 'lib/docx_tools/part_list.rb', line 24

def get(filename)
  parts[filename]
end

#has?(filename) ⇒ Boolean

true if this part list has extracted this part from the document

Returns:

  • (Boolean)


29
30
31
# File 'lib/docx_tools/part_list.rb', line 29

def has?(filename)
  parts.key?(filename)
end