Class: Dip::InteractionTree

Inherits:
Object
  • Object
show all
Defined in:
lib/dip/interaction_tree.rb

Instance Method Summary collapse

Constructor Details

#initialize(entries) ⇒ InteractionTree

Returns a new instance of InteractionTree.



10
11
12
# File 'lib/dip/interaction_tree.rb', line 10

def initialize(entries)
  @entries = entries
end

Instance Method Details

#find(name, *argv) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dip/interaction_tree.rb', line 14

def find(name, *argv)
  entry = entries[name.to_sym]
  return unless entry

  commands = expand(name.to_s, entry)

  keys = [name, *argv]
  rest = []

  keys.size.times do
    if (command = commands[keys.join(" ")])
      return {command: command, argv: rest.reverse!}
    else
      rest << keys.pop
    end
  end

  nil
end

#listObject



34
35
36
37
38
# File 'lib/dip/interaction_tree.rb', line 34

def list
  entries.each_with_object({}) do |(name, entry), memo|
    expand(name.to_s, entry, tree: memo)
  end
end