Class: Gamefic::UserStream

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/engine.rb

Direct Known Subclasses

Cgi::UserStream, Tty::UserStream

Instance Method Summary collapse

Constructor Details

#initializeUserStream

Returns a new instance of UserStream.



64
65
66
67
# File 'lib/gamefic/engine.rb', line 64

def initialize
  @queue = Array.new
  @buffer = ''
end

Instance Method Details

#flushObject



68
69
70
71
72
73
# File 'lib/gamefic/engine.rb', line 68

def flush
  tmp = @buffer.clone
  #@buffer.clear
  @buffer = ''
  tmp
end

#recvObject



86
87
88
# File 'lib/gamefic/engine.rb', line 86

def recv
  @queue.shift
end

#select(prompt) ⇒ Object



80
81
82
83
84
85
# File 'lib/gamefic/engine.rb', line 80

def select(prompt)
  print "#{prompt} "
  STDOUT.flush
  line = STDIN.gets
  @queue.push line.strip
end

#send(data) ⇒ Object



74
75
76
77
78
79
# File 'lib/gamefic/engine.rb', line 74

def send(data)
  # Quick and dirty HTML sanitization
  #data.gsub!(/<[a-z]+[^>]*>/i, "")
  #data.gsub!(/<\/[^>]*>/, "")
  @buffer += data
end