Class: Gamefic::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/command.rb

Overview

A concrete representation of an input as a verb and an array of arguments.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(verb, arguments, meta = false, input = nil) ⇒ Command



20
21
22
23
24
25
26
# File 'lib/gamefic/command.rb', line 20

def initialize(verb, arguments, meta = false, input = nil)
  @verb = verb
  @arguments = arguments
  @meta = meta
  @input = input
  @cancelled = false
end

Instance Attribute Details

#argumentsArray<Array<Entity>, Entity, String> (readonly)



11
12
13
# File 'lib/gamefic/command.rb', line 11

def arguments
  @arguments
end

#inputString? (readonly)



14
15
16
# File 'lib/gamefic/command.rb', line 14

def input
  @input
end

#verbSymbol (readonly)



8
9
10
# File 'lib/gamefic/command.rb', line 8

def verb
  @verb
end

Instance Method Details

#active?Boolean



42
43
44
# File 'lib/gamefic/command.rb', line 42

def active?
  !meta?
end

#cancelObject Also known as: stop



28
29
30
# File 'lib/gamefic/command.rb', line 28

def cancel
  @cancelled = true
end

#cancelled?Boolean Also known as: stopped?



33
34
35
# File 'lib/gamefic/command.rb', line 33

def cancelled?
  @cancelled
end

#inspectObject



46
47
48
# File 'lib/gamefic/command.rb', line 46

def inspect
  "#<#{self.class} #{([verb] + arguments).map(&:inspect).join(', ')}>"
end

#meta?Boolean



38
39
40
# File 'lib/gamefic/command.rb', line 38

def meta?
  @meta
end