Class: Dip::InteractionTree
- Inherits:
-
Object
- Object
- Dip::InteractionTree
- Defined in:
- lib/dip/interaction_tree.rb
Instance Method Summary collapse
- #find(name, *argv) ⇒ Object
-
#initialize(entries) ⇒ InteractionTree
constructor
A new instance of InteractionTree.
- #list ⇒ Object
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 = (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 |
#list ⇒ Object
34 35 36 37 38 |
# File 'lib/dip/interaction_tree.rb', line 34 def list entries.each_with_object({}) do |(name, entry), memo| (name.to_s, entry, tree: memo) end end |