Class: MiddleSquid::Backends::Keyboard
- Inherits:
-
EventMachine::Connection
- Object
- EventMachine::Connection
- MiddleSquid::Backends::Keyboard
- Defined in:
- lib/middle_squid/backends/keyboard.rb
Overview
Receives data from the standard input.
Instance Method Summary collapse
-
#initialize(handler) ⇒ Keyboard
constructor
A new instance of Keyboard.
- #receive_data(char) ⇒ Object
- #receive_line(line) ⇒ Object
Constructor Details
#initialize(handler) ⇒ Keyboard
Returns a new instance of Keyboard.
5 6 7 8 |
# File 'lib/middle_squid/backends/keyboard.rb', line 5 def initialize(handler) @buffer = [] @handler = handler end |
Instance Method Details
#receive_data(char) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/middle_squid/backends/keyboard.rb', line 11 def receive_data(char) case char when "\x00" EM.stop when "\n" line = @buffer.join @buffer.clear receive_line line else @buffer << char end end |
#receive_line(line) ⇒ Object
26 27 28 29 |
# File 'lib/middle_squid/backends/keyboard.rb', line 26 def receive_line(line) # EventMachine sends ASCII-8BIT strings, somehow preventing the databases queries to match @handler.call line.force_encoding(Encoding::UTF_8) end |