Module: Tree::Utils::TreePathHandler

Included in:
TreeNode
Defined in:
lib/tree/utils/path_methods.rb

Overview

Provides utility methods for path extraction

Node Path collapse

Instance Method Details

#path_as_arrayArray

Returns the node-names from this node to the root as an array. The first element is the root node name, and the last element is this node’s name.

node

Returns:

  • (Array)

    The array containing the node names for the path to this



64
65
66
# File 'lib/tree/utils/path_methods.rb', line 64

def path_as_array
  get_path_name_array.reverse
end

#path_as_string(separator = '=>') ⇒ String

Returns the path of this node from the root as a string, with the node names separated using the specified separator. The path is listed left to right from the root node.

Parameters:

  • separator (defaults to: '=>')

    The optional separator to use. The default separator is ‘+=>+’.

Returns:

  • (String)

    The node path with names separated using the specified separator.



55
56
57
# File 'lib/tree/utils/path_methods.rb', line 55

def path_as_string(separator = '=>')
  path_as_array.join(separator)
end