Module: Gardner
- Defined in:
- lib/sapling/gardner.rb
Overview
Gardner is the module for working with a dialogue tree file
Class Method Summary collapse
-
.prune_branches(tree) ⇒ Array
Parse the tree array into an array of numbered branches, and ordered leaves.
-
.prune_leaves(leaves) ⇒ Hash
Parse the leaves of a branch into a numbered hash of options.
-
.prune_trunk(tree) ⇒ Array
Parse the trunk of the tree.
Class Method Details
.prune_branches(tree) ⇒ Array
Parse the tree array into an array of numbered branches, and ordered leaves.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/sapling/gardner.rb', line 10 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 |
.prune_leaves(leaves) ⇒ Hash
Parse the leaves of a branch into a numbered hash of options.
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/sapling/gardner.rb', line 25 def self.prune_leaves(leaves) x = 1 = {} return if leaves.nil? leaves.each do |l| [x] = { l["text"] => l["branch"] } x += 1 end return end |
.prune_trunk(tree) ⇒ Array
Parse the trunk of the tree.
43 44 45 46 47 |
# File 'lib/sapling/gardner.rb', line 43 def self.prune_trunk(tree) trunk = tree.shift return [trunk,tree] end |