class DocTree::DocTreeNode
Attributes
attrs[RW]
name[RW]
Public Class Methods
forHTML(html)
click to toggle source
# File lib/doctree.rb, line 34 def self.forHTML(html) return DocTreeNode.new(html.title, html) if html.is_a? Nokogiri::XML::Document if html.name == 'a' node = DocTreeNode.new(html.text.strip, html) node.href = html["href"].to_s return node end raise "Unsupported node \"#{node.name}\", expected a Nokigiri XML/HTML document or <a> element" end
Public Instance Methods
href()
click to toggle source
# File lib/doctree.rb, line 17 def href attrs[:href] end
href=(new_value)
click to toggle source
# File lib/doctree.rb, line 21 def href=(new_value) attrs[:href] = new_value end
map_html_tree(html, &block)
click to toggle source
# File lib/doctree.rb, line 46 def map_html_tree(html, &block) parent = if result = block.call(html) then self << result else self end html.children.each { |c| parent.map_html_tree(c, &block) } end
string_value(depth = 0, indent = "\t", &block)
click to toggle source
# File lib/doctree.rb, line 29 def string_value(depth = 0, indent = "\t", &block) childStr = self.children.count > 0 ? "\n" + children.map{ |node| node.string_value(depth + 1, &block) }.join("\n") : "" return [indent * depth, block.call(self), childStr].join("") end
to_s()
click to toggle source
# File lib/doctree.rb, line 25 def to_s self.string_value { |node| node.name + if node.attrs and !node.attrs.empty? then " -- " + node.attrs.to_json.gsub("\n", "") else "" end } end