<commit_before>require 'yaml'

# Gardner is the module for working with a dialogue tree file
module Gardner

  # Parse the branch
  #
  # @param tree [Array] The dialogue tree
  # @return [Array] The array of options on the branch.
  def self.prune_branches(tree)
    branches = { 0 => { "desc" => "Thanks for using Sapling!" } }
    tree.each do |b|
      branches[b["branch"]["number"]] = {
        "desc" => b["branch"]["text"],
        "options" => prune_leaves(b["branch"]["leaf"]) }
    end

    return branches

  end

  # Parse the options
  #
  # @param leaves [Array] The option of leaf hashes
  # @return [Hash] A has of options
  def self.prune_leaves(leaves)
    x = 1
    options = {}

    return options if leaves.nil?

    leaves.each do |l|
      options[x] = { l["text"] => l["branch"] }
      x += 1
    end

    return options

  end

  # Parse the trunk
  # The trunk is like the introduction to the tree.
  #
  # @param tree [Hash] The entire tree
  # @return [Hash] The tree without the trunk
  def self.prune_trunk(tree)
    trunk = tree.shift
    40.times { print "-" }
    puts "\n#{trunk["trunk"]}"
    40.times { print "-" }
    puts "\n"

    return tree

  end

  # The main method for Sapling. From here, the tree is grown.
  #
  # @param tree [File] The dialogue tree file
  # @return [Hash] The final, constructed data set
  def self.grow(tree)
      trunk = Gardner.prune_trunk(tree)
      branches = Gardner.prune_branches(trunk)

      return branches
  end

end<commit_msg>gardner.rb: Refactor<commit_after>require 'yaml'

# Gardner is the module for working with a dialogue tree file
module Gardner
  # Parse the tree array into an array of numbered branches, and ordered leaves.
  #
  # @param tree [Array] The dialogue tree
  # @return [Array] An array of numbered branches, with numbered leaves
  def self.prune_branches(tree)
    branches = { 0 => { "desc" => "Thanks for using Sapling!" } }
    tree.each do |b|
      branches[b["branch"]["number"]] = {
        "desc" => b["branch"]["text"],
        "options" => prune_leaves(b["branch"]["leaf"]) }
    end

    return branches
  end

  # Parse the leaves of a branch into a numbered hash of options.
  #
  # @param leaves [Array] The option of leaf hashes
  # @return [Hash] A numbered hash of options
  def self.prune_leaves(leaves)
    x = 1
    options = {}

    return options if leaves.nil?

    leaves.each do |l|
      options[x] = { l["text"] => l["branch"] }
      x += 1
    end

    return options
  end

  # Parse the trunk of the tree.
  #
  # @param tree [Hash] The entire tree
  # @return [Array] The trunk, and the remainder of the tree
  def self.prune_trunk(tree)
    trunk = tree.shift

    return [trunk,tree]
  end
end
{'fraction_non_alphanumeric': 0.1185076810534016, 'fraction_numerical': 0.0036576444769568397, 'mean_word_length': 2.7517146776406034, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2449118', 'n_tokens_mistral': 907, 'n_tokens_neox': 888, 'n_words': 310}