Class: Bane::Behaviors::Responders::SlowResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/bane/behaviors/responders/slow_response.rb

Overview

Sends a fixed response character-by-character, pausing between each character.

Options:

- message: The response to send. Default: "Hello, world!"
- pause_duration: The number of seconds to pause between each character. Default: 10 seconds

Direct Known Subclasses

SlowResponseForEachLine

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SlowResponse

Returns a new instance of SlowResponse.



13
14
15
# File 'lib/bane/behaviors/responders/slow_response.rb', line 13

def initialize(options = {})
  @options = {message: "Hello, world!", pause_duration: 10}.merge(options)
end

Instance Method Details

#serve(io) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/bane/behaviors/responders/slow_response.rb', line 17

def serve(io)
  message = @options[:message]
  pause_duration = @options[:pause_duration]

  message.each_char do |char|
    io.write char
    sleep pause_duration
  end
end