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.



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

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

Instance Method Details

#flushObject



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

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

#recvObject



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

def recv
  @queue.shift
end

#select(prompt) ⇒ Object



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

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

#send(data) ⇒ Object



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

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