Class: Kerplutz::CommandMap

Inherits:
Object
  • Object
show all
Defined in:
lib/kerplutz/command_map.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCommandMap

Returns a new instance of CommandMap.



5
6
7
# File 'lib/kerplutz/command_map.rb', line 5

def initialize
  @commands = {}
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



3
4
5
# File 'lib/kerplutz/command_map.rb', line 3

def commands
  @commands
end

Instance Method Details

#<<(command) ⇒ Object



13
14
15
# File 'lib/kerplutz/command_map.rb', line 13

def <<(command)
  add(command) and return self
end

#===(display_name) ⇒ Object



25
26
27
# File 'lib/kerplutz/command_map.rb', line 25

def ===(display_name)
  commands.has_key?(display_name)
end

#[](display_name) ⇒ Object



17
18
19
# File 'lib/kerplutz/command_map.rb', line 17

def [](display_name)
  commands[display_name]
end

#add(command) ⇒ Object



9
10
11
# File 'lib/kerplutz/command_map.rb', line 9

def add(command)
  commands[command.display_name] = command
end

#has_command?(display_name) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/kerplutz/command_map.rb', line 21

def has_command?(display_name)
  self.===(display_name)
end

#summary(indent = 2) ⇒ Object



29
30
31
32
33
# File 'lib/kerplutz/command_map.rb', line 29

def summary(indent=2)
  commands.inject("") do |acc, (display_name, command)|
    acc << " " * indent << "#{display_name} #{command.desc}\n"
  end
end