Class: Uniword::Docx::PartLoader::LoadContext

Inherits:
Object
  • Object
show all
Defined in:
lib/uniword/docx/part_loader/load_context.rb

Overview

Shared state for one package load: the extracted ZIP entries, the package being populated, and the main-document paths resolved from the package-level relationships.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zip_content:, package:, zip_path: nil) ⇒ LoadContext

Returns a new instance of LoadContext.

Parameters:

  • zip_content (Hash)

    extracted ZIP entries

  • package (Package)

    package being populated

  • zip_path (String, nil) (defaults to: nil)

    original ZIP path



23
24
25
26
27
# File 'lib/uniword/docx/part_loader/load_context.rb', line 23

def initialize(zip_content:, package:, zip_path: nil)
  @zip_content = zip_content
  @package = package
  @zip_path = zip_path
end

Instance Attribute Details

#packagePackage (readonly)

Returns package being populated.

Returns:

  • (Package)

    package being populated



14
15
16
# File 'lib/uniword/docx/part_loader/load_context.rb', line 14

def package
  @package
end

#zip_contentHash (readonly)

Returns extracted ZIP entries (package path => content).

Returns:

  • (Hash)

    extracted ZIP entries (package path => content)



11
12
13
# File 'lib/uniword/docx/part_loader/load_context.rb', line 11

def zip_content
  @zip_content
end

#zip_pathString? (readonly)

Returns original ZIP path for binary re-extraction.

Returns:

  • (String, nil)

    original ZIP path for binary re-extraction



18
19
20
# File 'lib/uniword/docx/part_loader/load_context.rb', line 18

def zip_path
  @zip_path
end

Instance Method Details

#main_document_pathString?

Main document part path, resolved from the package-level officeDocument relationship.

Returns:

  • (String, nil)

    e.g. "word/document.xml"



42
43
44
45
46
# File 'lib/uniword/docx/part_loader/load_context.rb', line 42

def main_document_path
  return @main_document_path if defined?(@main_document_path)

  @main_document_path = find_main_document_path
end

#main_document_rels_pathString?

Relationships part path of the main document, derived from its resolved path.

Returns:

  • (String, nil)

    e.g. "word/_rels/document.xml.rels"



52
53
54
55
56
# File 'lib/uniword/docx/part_loader/load_context.rb', line 52

def main_document_rels_path
  return @main_document_rels_path if defined?(@main_document_rels_path)

  @main_document_rels_path = sidecar_rels_path(main_document_path)
end

#matching_paths(definition) ⇒ Array<String>

Zip entry paths matching the definition's fixed path or path pattern (numbered part families).

Parameters:

Returns:

  • (Array<String>)

    in zip_content order



34
35
36
# File 'lib/uniword/docx/part_loader/load_context.rb', line 34

def matching_paths(definition)
  zip_content.keys.select { |path| definition.match_path?(path) }
end