class ODFWriter::ImageReader

ImageReader: find all images and set name

Attributes

name[RW]

Public Class Methods

new(opts) click to toggle source

initialize

# File lib/odf_writer/image_reader.rb, line 38
def initialize(opts)
  @name = opts[:name]
end

Public Instance Methods

paths( root, doc) click to toggle source

get_paths: limit to paths with ancestors 'text '(content.xml) and master-styles (styles.xml)

# File lib/odf_writer/image_reader.rb, line 47
def paths( root, doc)
  
  # find nodes with matching field elements matching [BOOKMARK] pattern
  nodes = doc.xpath("//draw:frame[draw:image]").select{|node| scan(node).present? }
  
  # find path for each field
  paths = nil
  nodes.each do |node|
    leaf  = {:images => scan(node)}
    paths = PathFinder.trail(node, leaf, :root => root, :paths => paths)
  end #each
  paths.to_h
  
end

Private Instance Methods

scan(node) click to toggle source

private

# File lib/odf_writer/image_reader.rb, line 68
def scan(node)
  if name 
    node.attr("draw:name") == name.upcase ? [node.attr("draw:name")] : []
  else
    [node.attr("draw:name")]
  end
end