Class: Hirb::Helpers::Tree

### Home Classes Methods

### In Files

- lib/hirb/helpers/tree.rb

### Parent

Object

### Namespace

- CLASS Hirb::Helpers::Tree::Node
- CLASS Hirb::Helpers::Tree::ParentlessNodeError

### Methods

- ::render

### Files

- LICENSE.txt
- README.rdoc

### Class/Module Index

Quicksearch

- Hirb
- Hirb::Console
- Hirb::DynamicView
- Hirb::Formatter
- Hirb::Helpers
- Hirb::Helpers::AutoTable
- Hirb::Helpers::ObjectTable
- Hirb::Helpers::ParentChildTree
- Hirb::Helpers::Table
- Hirb::Helpers::Table::Filters
- Hirb::Helpers::Table::Resizer
- Hirb::Helpers::Table::TooManyFieldsForWidthError
- Hirb::Helpers::Tree
- Hirb::Helpers::Tree::Node
- Hirb::Helpers::Tree::Node::MissingLevelError
- Hirb::Helpers::Tree::Node::MissingValueError
- Hirb::Helpers::Tree::ParentlessNodeError
- Hirb::Helpers::VerticalTable
- Hirb::Menu
- Hirb::Menu::Error
- Hirb::ObjectMethods
- Hirb::Pager
- Hirb::String
- Hirb::Util
- Hirb::View
- Hirb::Views

No matching classes.

# Hirb::Helpers::Tree

Base tree class which given an array of nodes produces different types of trees. The types of trees currently are:

- basic:

      0
        1
          2
          3
        4

- directory:

      0
      |-- 1
      |   |-- 2
      |   `-- 3
      `-- 4

- number:

      1. 0
        1. 1
          1. 2
          2. 3
        2. 4

Tree nodes can be given as an array of arrays or an array of hashes. To render the above basic tree with an array of hashes:

    Hirb::Helpers::Tree.render([{:value=>0, :level=>0}, {:value=>1, :level=>1}, {:value=>2, :level=>2},
      {:value=>3, :level=>2}, {:value=>4, :level=>1}])

Note from the hash keys that :level refers to the depth of the tree while :value refers to the text displayed for a node.

To render the above basic tree with an array of arrays:

    Hirb::Helpers::Tree.render([[0,0], [1,1], [2,2], [2,3], [1,4]])

Note that the each array pair consists of the level and the value for the node.

### Public Class Methods

render(nodes, options={}) click to toggle source

Main method which renders a tree.

#### Options:

:type

  Type of tree. Either :basic, :directory or :number. Default is :basic.

:validate

  Boolean to validate tree. Checks to see if all nodes have parents. Raises ParentlessNodeError if an invalid node is found. Default is false.

:indent

  Number of spaces to indent between levels for basic + number trees. Default is 4.

:limit

  Limits the level or depth of a tree that is displayed. Root node is level 0.

:description

  Displays brief description about tree ie how many nodes it has.

:multi_line_nodes

  Handles multi-lined nodes by indenting their newlines. Default is false.

    Examples:
       Hirb::Helpers::Tree.render([[0, 'root'], [1, 'child']], :type=>:directory)

    # File lib/hirb/helpers/tree.rb, line 49
    def render(nodes, options={})
      new(nodes, options).render
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.