Class: Coradoc::Docx::Transform::Rules::ImageRule

Inherits:
Coradoc::Docx::Transform::Rule show all
Defined in:
lib/coradoc/docx/transform/rules/image_rule.rb

Overview

Transforms w:drawing and w:pict elements to CoreModel::Image.

Extracts image reference data (relationship ID, dimensions, alt text). Binary data extraction is handled by the caller via the image_refs list in Context.

Instance Method Summary collapse

Methods inherited from Coradoc::Docx::Transform::Rule

#priority

Instance Method Details

#apply(element, context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/coradoc/docx/transform/rules/image_rule.rb', line 20

def apply(element, context)
  ref = extract_reference(element)
  context.register_image(ref)

  CoreModel::Image.new(
    src: ref[:src],
    alt: ref[:alt],
    width: ref[:width],
    height: ref[:height],
    inline: ref[:inline]
  )
end

#matches?(element) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
# File 'lib/coradoc/docx/transform/rules/image_rule.rb', line 13

def matches?(element)
  return false unless defined?(Uniword::Wordprocessingml)

  element.is_a?(Uniword::Wordprocessingml::Drawing) ||
    element.is_a?(Uniword::Wordprocessingml::Picture)
end