Class: Bane::Behaviors::SlowResponse

Inherits:
BasicBehavior show all
Defined in:
lib/bane/behaviors.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

Methods inherited from BasicBehavior

inherited, simple_name

Constructor Details

#initialize(options = {}) ⇒ SlowResponse

Returns a new instance of SlowResponse.



99
100
101
# File 'lib/bane/behaviors.rb', line 99

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

Instance Method Details

#serve(io) ⇒ Object



103
104
105
106
107
108
109
110
111
# File 'lib/bane/behaviors.rb', line 103

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

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