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.



11
12
13
# File 'lib/bane/behaviors/responders/slow_response.rb', line 11

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

Instance Method Details

#serve(io) ⇒ Object



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

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

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