Skip to content
zverok edited this page Aug 7, 2015 · 9 revisions

Infoboxer page tree consists of nodes. Node is some piece of document, which either contains text (Text node), or other nodes (like Italic with text inside or Paragraph), or it can be empty (HR node or BR node).

The basic methods for each node are:

  • Node#text -- plaintext representation of node contents (see also: Node text gotchas)
  • Node#params -- for example, {level: 3} for heading, or {class: 'wikitable'} for table
  • Node#children (for all compound nodes) and Node#parent

Also, many nodes has some convinience methods and additional attributes, like Wikilink#link, or Image#caption, or Template#name -- all of them can be found in API docs.

Nodes collection

When infoboxer returns you list of nodes, it is wrapped in Nodes class, which is basically Array with some additions like:

  • Nodes#text returns joined text of all nodes
  • Methods like #fetch (template variable), #follow (wikilink) and similar, as well as generic tree lookup methods, are dispatched to all nodes able to respond, and responses are returned as consolidated Nodes array again.

The idea is simple and already seen in DOM tree navigators like Nokogiri or jQuery: in most common cases you can work with list of nodes the same way you work with only node.

See also API docs.

Next: Tree navigation basics