Class: XMLColFinder
- Inherits:
-
Object
- Object
- XMLColFinder
- Defined in:
- lib/xml_col_finder.rb
Overview
note: There’s a to_code method which makes it convenient to fetch the
values from the generated code.
Instance Attribute Summary collapse
-
#to_a ⇒ Object
readonly
Returns the value of attribute to_a.
Instance Method Summary collapse
-
#initialize(obj, debug: false) ⇒ XMLColFinder
constructor
A new instance of XMLColFinder.
- #to_code(nametip: true) ⇒ Object
- #to_doc ⇒ Object
Constructor Details
#initialize(obj, debug: false) ⇒ XMLColFinder
Returns a new instance of XMLColFinder.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/xml_col_finder.rb', line 25 def initialize(obj, debug: false) @debug = debug @doc = obj.is_a?(Rexle) ? obj : Rexle.new(obj) a = [] @doc.root.each_recursive do |node| if node.text and node.text.strip.length >= 1 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.
23 24 25 |
# File 'lib/xml_col_finder.rb', line 23 def to_a @to_a end |
Instance Method Details
#to_code(nametip: true) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/xml_col_finder.rb', line 46 def to_code(nametip: true) @nametip = nametip @tags = {} xpath, remaining = @to_a eid = getid(xpath) linex = formatline('doc', eid, xpath) a = scan(remaining, eid) lines = a.flatten.compact.prepend linex lines2 = lines.join("\n").lines\ .map {|line| line =~ /.text$/ ? 'puts ' + line : line } lines2[0].sub!(/(?<=\")div/,'//div') s = "require 'nokorexi' url = 'https://insert-your-url' doc = Nokorexi.new(url).to_doc " + lines2.join Clipboard.copy s return s end |
#to_doc ⇒ Object
72 73 74 |
# File 'lib/xml_col_finder.rb', line 72 def to_doc() @doc end |