Class: CommandSuggestor
- Inherits:
-
Object
- Object
- CommandSuggestor
- Defined in:
- lib/command/command_suggestor.rb
Instance Attribute Summary collapse
-
#wordtree ⇒ Object
Returns the value of attribute wordtree.
Instance Method Summary collapse
- #add(line) ⇒ Object
- #commands ⇒ Object
-
#initialize ⇒ CommandSuggestor
constructor
A new instance of CommandSuggestor.
- #to_tree ⇒ Object
- #truncate!(minimum) ⇒ Object
Constructor Details
#initialize ⇒ CommandSuggestor
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
#wordtree ⇒ Object
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 |
#commands ⇒ Object
18 19 20 |
# File 'lib/command/command_suggestor.rb', line 18 def commands wordtree.root.children.keys end |
#to_tree ⇒ Object
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 |