class ODFWriter::FieldReader
FieldReader: find all fields and set name
Attributes
name[RW]
Public Class Methods
new(opts={})
click to toggle source
initialize
# File lib/odf_writer/field_reader.rb, line 38 def initialize(opts={}) @name = opts[:name] end
Public Instance Methods
paths( file, doc)
click to toggle source
paths
# File lib/odf_writer/field_reader.rb, line 47 def paths( file, doc) # find nodes with matching field elements matching [FIELD] pattern nodes = doc.xpath("//text()").select{|node| scan(node).present? } # find path for each field paths = nil nodes.each do |node| leaf = {:fields => scan(node)} paths = PathFinder.trail(node, leaf, :root => file, :paths => paths) end #each paths.to_h end
Private Instance Methods
scan(node)
click to toggle source
private
# File lib/odf_writer/field_reader.rb, line 69 def scan(node) if name node.text.scan(/(?<=#{Regexp.escape Field::DELIMITERS[0]})#{name.upcase}(?=#{Regexp.escape Field::DELIMITERS[1]})/) else node.text.scan(/(?<=#{Regexp.escape Field::DELIMITERS[0]})[A-Z0-9_]+?(?=#{Regexp.escape Field::DELIMITERS[1]})/) end end