module Gamefic::Messaging

Public Instance Methods

flush() click to toggle source

Clear the buffered messages.

# File lib/gamefic/messaging.rb, line 29
def flush
  @messages = ''
end
messages() click to toggle source

Get all the currently buffered messages consolidated in a single string.

@return [String]

# File lib/gamefic/messaging.rb, line 23
def messages
  @messages ||= ''
end
stream(message) click to toggle source

Send a message to the Character as raw text. Unlike tell, this method will not wrap the message in HTML paragraphs.

@param message [String]

# File lib/gamefic/messaging.rb, line 16
def stream(message)
  @messages = @messages.to_s + message
end
tell(message) click to toggle source

Send a message to the entity. This method will automatically wrap the message in HTML paragraphs. To send a message without paragraph formatting, use stream instead.

@param message [String]

# File lib/gamefic/messaging.rb, line 8
def tell(message)
  @messages = @messages.to_s + format(message)
end

Private Instance Methods

format(message) click to toggle source
# File lib/gamefic/messaging.rb, line 35
def format message
  "<p>#{message.strip}</p>"
    .gsub(/[ \t\r]*\n[ \t\r]*\n[ \t\r]*/, "</p><p>")
    .gsub(/[ \t]*\n[ \t]*/, ' ')
    .gsub(/<p>[\s]*<p>/, '<p>')
    .gsub(/<\/p>[\s]*<\/p>/, '</p>')
end