Class: CommandSuggestor

Inherits:
Object
  • Object
show all
Defined in:
lib/command/command_suggestor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandSuggestor

Returns a new instance of CommandSuggestor.



4
5
6
# File 'lib/command/command_suggestor.rb', line 4

def initialize()
  @wordtree = WordTree.new
end

Instance Attribute Details

#wordtreeObject

Returns the value of attribute wordtree.



2
3
4
# File 'lib/command/command_suggestor.rb', line 2

def wordtree
  @wordtree
end

Instance Method Details

#add(line) ⇒ Object



8
9
10
11
12
# File 'lib/command/command_suggestor.rb', line 8

def add(line)
  sl = ScriptLine.new(line)
  return unless sl.valid?
  wordtree.add(sl)
end

#commandsObject



18
19
20
# File 'lib/command/command_suggestor.rb', line 18

def commands
  wordtree.root.children.keys
end

#to_treeObject



22
23
24
25
26
27
# File 'lib/command/command_suggestor.rb', line 22

def to_tree
  wordtree.root.map do |n|
    cs = CommandSuggestion.new(n.word_list)
    "#{n.to_tree.chomp} #{cs.to_s}"
  end
end

#truncate!(minimum) ⇒ Object



14
15
16
# File 'lib/command/command_suggestor.rb', line 14

def truncate!(minimum)
  wordtree.root.truncate!(minimum)
end