Class: XMLColFinder
- Inherits:
-
Object
- Object
- XMLColFinder
- Defined in:
- lib/xml_col_finder.rb
Instance Attribute Summary collapse
-
#to_a ⇒ Object
readonly
Returns the value of attribute to_a.
Instance Method Summary collapse
-
#initialize(s, debug: false) ⇒ XMLColFinder
constructor
A new instance of XMLColFinder.
- #to_code(nametip: true) ⇒ Object
Constructor Details
#initialize(s, debug: false) ⇒ XMLColFinder
Returns a new instance of XMLColFinder.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/xml_col_finder.rb', line 12 def initialize(s, debug: false) @debug = debug doc = Rexle.new(s) a = [] doc.root.each_recursive do |node| if node.text then a << [BacktrackXPath.new(node, ignore_id: true).to_xpath.split('/'), node.text] end end #@to_a = a h = group_by_xpath(a) @to_a = truncate_xpath(h).flatten(1) end |
Instance Attribute Details
#to_a ⇒ Object (readonly)
Returns the value of attribute to_a.
10 11 12 |
# File 'lib/xml_col_finder.rb', line 10 def to_a @to_a end |
Instance Method Details
#to_code(nametip: true) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/xml_col_finder.rb', line 33 def to_code(nametip: true) @nametip = nametip = {} xpath, remaining = @to_a eid = getid(xpath) linex = formatline('doc', eid, xpath) a = scan(remaining, eid) lines = a.flatten.compact.prepend linex lines.join("\n").lines\ .map {|line| line =~ /.text$/ ? 'puts ' + line : line }.join end |