Class: FourTwoSeven::Command

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

Constant Summary collapse

KEYS =
[
  *"A".."Z", 
  *"a".."z", 
  *"0".."9",
  " "
]
DURATION =
0..15
PROMPT =
"> Please PRESS '%s' on your KEYBOARD for %ss.\n"
SEPARATOR =
"\n\n- - -\n"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(prev_command = nil) ⇒ Command

Returns a new instance of Command.



19
20
21
# File 'lib/427/command.rb', line 19

def initialize(prev_command = nil)
  @prev_command = prev_command
end

Instance Attribute Details

#prev_commandObject

Returns the value of attribute prev_command.



17
18
19
# File 'lib/427/command.rb', line 17

def prev_command
  @prev_command
end

Instance Method Details

#durationObject



31
32
33
34
# File 'lib/427/command.rb', line 31

def duration
  0
  #@duration ||= rand(DURATION)
end

#keyObject



23
24
25
26
27
28
29
# File 'lib/427/command.rb', line 23

def key
  @key ||= if prev_command
    KEYS - [prev_command.key]
  else
    KEYS
  end.sample
end

#promptObject



36
37
38
# File 'lib/427/command.rb', line 36

def prompt
  PROMPT % [key, duration]
end