Module: Gardner
- Defined in:
- lib/sapling/gardner.rb
Overview
Gardner is the module for working with a dialogue tree file
Class Method Summary collapse
-
.grow(tree) ⇒ Hash
The main method for Sapling.
-
.prune_branches(tree) ⇒ Array
Parse the branch.
-
.prune_leaves(leaves) ⇒ Hash
Parse the options.
-
.prune_trunk(tree) ⇒ Hash
Parse the trunk The trunk is like the introduction to the tree.
Class Method Details
.grow(tree) ⇒ Hash
The main method for Sapling. From here, the tree is grown.
61 62 63 64 65 66 |
# File 'lib/sapling/gardner.rb', line 61 def self.grow(tree) trunk = Gardner.prune_trunk(tree) branches = Gardner.prune_branches(trunk) return branches end |
.prune_branches(tree) ⇒ Array
Parse the branch
10 11 12 13 14 15 16 17 18 19 20 |
# 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 options
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sapling/gardner.rb', line 26 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) ⇒ Hash
Parse the trunk The trunk is like the introduction to the tree.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/sapling/gardner.rb', line 46 def self.prune_trunk(tree) trunk = tree.shift 40.times { print "-" } puts "\n#{trunk["trunk"]}" 40.times { print "-" } puts "\n" return tree end |