Class: ODFWriter::BookmarkReader

Inherits:
Object
  • Object
show all
Defined in:
lib/odf_writer/bookmark_reader.rb

Overview

BookmarkReader: find all bookmarks and set name

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BookmarkReader

initialize



38
39
40
# File 'lib/odf_writer/bookmark_reader.rb', line 38

def initialize(opts={})
  @name = opts[:name]
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



31
32
33
# File 'lib/odf_writer/bookmark_reader.rb', line 31

def name
  @name
end

Instance Method Details

#paths(root, doc) ⇒ Object

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



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/odf_writer/bookmark_reader.rb', line 47

def paths( root, doc)
  
  # find nodes with matching field elements matching [BOOKMARK] pattern
  nodes = doc.xpath("//*[self::text:bookmark or self::text:bookmark-start]").select{|node| scan(node).present? }
  
  # find path for each field
  paths = nil
  nodes.each do |node|
    leaf  = {:bookmarks => scan(node)}
    paths = PathFinder.trail(node, leaf, :root => root, :paths => paths)
  end #each
  paths.to_h
  
end