Class: DocxTools::PartList
- Inherits:
-
Object
- Object
- DocxTools::PartList
- Defined in:
- lib/docx_tools/part_list.rb
Instance Attribute Summary collapse
-
#parts ⇒ Object
the stored list of parts.
Instance Method Summary collapse
-
#each_part(&block) ⇒ Object
yield each part to the block.
-
#get(filename) ⇒ Object
get the requested part.
-
#has?(filename) ⇒ Boolean
true if this part list has extracted this part from the document.
-
#initialize(document, content_types) ⇒ PartList
constructor
parse the content type entries out of the given document.
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
#parts ⇒ Object
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
29 30 31 |
# File 'lib/docx_tools/part_list.rb', line 29 def has?(filename) parts.key?(filename) end |