Class: Harp::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/harp/command_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Command

Returns a new instance of Command.



48
49
50
51
# File 'lib/harp/command_manager.rb', line 48

def initialize(name)
  @name = name
  @blocks = {}
end

Instance Method Details

#add_spec(spec, block) ⇒ Object



53
54
55
56
# File 'lib/harp/command_manager.rb', line 53

def add_spec(spec, block)
  # TODO validate block and arity
  @blocks[spec]= block
end

#block_for(args) ⇒ Object



58
59
60
61
62
63
64
65
# File 'lib/harp/command_manager.rb', line 58

def block_for(args)
  @blocks.each do |spec, block|
    if match(spec, args)
      return block
    end
  end
  return nil
end

#match(spec, args) ⇒ Object



67
68
69
# File 'lib/harp/command_manager.rb', line 67

def match(spec, args)
  spec.size == args.size
end