Class: Planter::Spade

Inherits:
Object
  • Object
show all
Defined in:
lib/sapling/planter.rb

Overview

Utilities for editing specific parts of a tree.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#file=(value) ⇒ Object (writeonly)

The file we parse into a tree



18
19
20
# File 'lib/sapling/planter.rb', line 18

def file=(value)
  @file = value
end

Instance Method Details

#dig(branch_no) ⇒ Object

Function for displaying a single branch in debug mode. We also always display the trunk, since otherwise it's displayed a single time then gone forever (until next time).

Parameters:

  • branch_no (Integer)

    The number of the branch to be displayed.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/sapling/planter.rb', line 36

def dig(branch_no)
  branch = @plot.branches[branch_no]

  # Print the trunk
  40.times { print "-" }
  puts "\n[ Trunk ]\n#{@plot.trunk}"
  40.times { print "-" }
  puts "\n"
  10.times { print "*" }

  # Print the branch and options
  puts "\n[ Branch: #{branch_no} ]"
  puts "\n#{branch["desc"]}\n\n"
  unless branch["options"].empty?
    branch["options"].each_pair do |k,v|
      puts "\t#{k}: #{v.keys[0]}"
      puts "\t\t [ Goes to branch #{v.values[0]} ]"
    end
  end
end

#edit_branch(branch) ⇒ Object

Edit a branch on the tree

Parameters:

  • branch (Integer)

    The number of the branch to be edited.



65
66
67
# File 'lib/sapling/planter.rb', line 65

def edit_branch(branch)

end

#edit_leaf(branch, leaf) ⇒ Object

Edit a leaf on a branch, grasshopper

Parameters:

  • branch (Integer)

    The number of the branch to be edited.

  • leaf (Hash)

    The leaf hash to be edited.



73
74
75
# File 'lib/sapling/planter.rb', line 73

def edit_leaf(branch, leaf)

end

#edit_trunkObject

Edit the trunk of the tree



58
59
60
# File 'lib/sapling/planter.rb', line 58

def edit_trunk

end

#plantObject

Establish a new Plot, which is basically an object for storing information for us. From here, we start gardening.



22
23
24
25
26
27
28
29
# File 'lib/sapling/planter.rb', line 22

def plant
  @plot = Plot.new
  @plot.tree = @file
  @plot.trunk = @file.shift.values[0]
  @plot.branches = Gardner.prune_branches(@file)

  dig(1)
end