Class: Coradoc::Docx::Transform::Context
- Inherits:
-
Object
- Object
- Coradoc::Docx::Transform::Context
- Defined in:
- lib/coradoc/docx/transform/context.rb
Overview
Shared context for a single OOXML → CoreModel transform pass.
Holds resolvers, footnote content, image references, and the rule registry. Passed to every rule’s #apply method so rules can delegate sub-transforms (e.g., transform runs inside a paragraph).
Instance Attribute Summary collapse
-
#footnotes ⇒ Object
readonly
Returns the value of attribute footnotes.
-
#image_refs ⇒ Object
readonly
Returns the value of attribute image_refs.
-
#numbering_resolver ⇒ Object
readonly
Returns the value of attribute numbering_resolver.
-
#registry ⇒ Object
readonly
Returns the value of attribute registry.
-
#style_resolver ⇒ Object
readonly
Returns the value of attribute style_resolver.
Instance Method Summary collapse
-
#footnote_content(id) ⇒ String?
Fetch footnote content by ID.
-
#initialize(styles_configuration: nil, numbering_configuration: nil, footnotes: {}, registry: nil) ⇒ Context
constructor
A new instance of Context.
-
#register_image(ref) ⇒ Object
Record an image reference for later extraction.
-
#transform(element) ⇒ Coradoc::CoreModel::Base, ...
Transform an element using the registry.
Constructor Details
#initialize(styles_configuration: nil, numbering_configuration: nil, footnotes: {}, registry: nil) ⇒ Context
Returns a new instance of Context.
20 21 22 23 24 25 26 27 |
# File 'lib/coradoc/docx/transform/context.rb', line 20 def initialize(styles_configuration: nil, numbering_configuration: nil, footnotes: {}, registry: nil) @style_resolver = StyleResolver.new(styles_configuration) @numbering_resolver = NumberingResolver.new(numbering_configuration) @footnotes = footnotes @image_refs = [] @registry = registry end |
Instance Attribute Details
#footnotes ⇒ Object (readonly)
Returns the value of attribute footnotes.
13 14 15 |
# File 'lib/coradoc/docx/transform/context.rb', line 13 def footnotes @footnotes end |
#image_refs ⇒ Object (readonly)
Returns the value of attribute image_refs.
13 14 15 |
# File 'lib/coradoc/docx/transform/context.rb', line 13 def image_refs @image_refs end |
#numbering_resolver ⇒ Object (readonly)
Returns the value of attribute numbering_resolver.
13 14 15 |
# File 'lib/coradoc/docx/transform/context.rb', line 13 def numbering_resolver @numbering_resolver end |
#registry ⇒ Object (readonly)
Returns the value of attribute registry.
13 14 15 |
# File 'lib/coradoc/docx/transform/context.rb', line 13 def registry @registry end |
#style_resolver ⇒ Object (readonly)
Returns the value of attribute style_resolver.
13 14 15 |
# File 'lib/coradoc/docx/transform/context.rb', line 13 def style_resolver @style_resolver end |
Instance Method Details
#footnote_content(id) ⇒ String?
Fetch footnote content by ID
44 45 46 47 48 49 50 51 52 53 |
# File 'lib/coradoc/docx/transform/context.rb', line 44 def footnote_content(id) return nil unless id paragraphs = @footnotes[id.to_s] return nil unless paragraphs paragraphs.map do |para| extract_paragraph_text(para) end.join("\n") end |
#register_image(ref) ⇒ Object
Record an image reference for later extraction
58 59 60 |
# File 'lib/coradoc/docx/transform/context.rb', line 58 def register_image(ref) @image_refs << ref end |
#transform(element) ⇒ Coradoc::CoreModel::Base, ...
Transform an element using the registry
33 34 35 36 37 38 |
# File 'lib/coradoc/docx/transform/context.rb', line 33 def transform(element) return nil if element.nil? rule = @registry.find_rule(element) rule.apply(element, self) end |