extractWayFromTree = (tree, line) ->
  lines = tree.split '\n'
  way = []
  while line?
    way.unshift lines[line]
    line = getParentLine lines, line
  way.join '\n'

getIndentation = (line) ->
  line.match(/^ */)[0].length

getParentLine = (lines, line) ->
  childIndentation = getIndentation lines[line]
  while line > 0
    line--
    if childIndentation - 2 is getIndentation lines[line]
      return line
  null

module.exports = {extractWayFromTree}
