Method: SimpleTree#tree_rep

Defined in:
lib/filetree/simple_tree.rb

#tree_rep(depth = 0) ⇒ Object

Helper method for to_s, returns a tree representation of the subtree rooted at this node. This assumes some sort of identifier is specified for the object being called (self.name, self.identifier, etc)



168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
# File 'lib/filetree/simple_tree.rb', line 168

def tree_rep(depth=0)
  if self.name
    ident = self.name
  elsif self.identifier
    ident = self.identifier
  else
    ident = self.object_id
  end
  if depth > 0
    outp = " #{(["    "] * (depth - 1)).join("|")}\\- #{ident}\n"
  else
    outp = "#{ident}\n"
  end
  children.each do |child|
    outp += child.tree_rep(depth + 1)
  end
  outp
end