Class: Async::IO::Protocol::Line
- Inherits:
-
Generic
- Object
- Wrapper
- Generic
- Async::IO::Protocol::Line
show all
- Defined in:
- lib/async/io/protocol/line.rb
Constant Summary
Constants inherited
from Generic
Generic::WRAPPERS
Instance Attribute Summary collapse
Attributes inherited from Generic
#timeout
Instance Method Summary
collapse
Methods inherited from Generic
#connected?, #dup, #nonblock, #nonblock=, #nonblock?, #read, #wait, wrap, wrap_blocking_method, wraps, #write
Constructor Details
#initialize(stream, eol = $/) ⇒ Line
Returns a new instance of Line.
27
28
29
30
31
|
# File 'lib/async/io/protocol/line.rb', line 27
def initialize(stream, eol = $/)
super(stream)
@eol = eol
end
|
Instance Attribute Details
#eol ⇒ Object
Returns the value of attribute eol.
33
34
35
|
# File 'lib/async/io/protocol/line.rb', line 33
def eol
@eol
end
|
Instance Method Details
#each_line ⇒ Object
62
63
64
65
66
67
68
|
# File 'lib/async/io/protocol/line.rb', line 62
def each_line
return to_enum(:each_line) unless block_given?
while line = @stream.read_until(@eol)
yield line
end
end
|
#peek_line ⇒ Object
52
53
54
55
56
57
58
59
60
|
# File 'lib/async/io/protocol/line.rb', line 52
def peek_line
@stream.peek do |read_buffer|
if index = read_buffer.index(@eol)
return read_buffer.slice(0, index)
end
end
raise EOFError
end
|
#read_line ⇒ Object
48
49
50
|
# File 'lib/async/io/protocol/line.rb', line 48
def read_line
@stream.read_until(@eol) or @stream.eof!
end
|
#read_lines ⇒ Object
70
71
72
|
# File 'lib/async/io/protocol/line.rb', line 70
def read_lines
@stream.read.split(@eol)
end
|
#write_lines(*args) ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/async/io/protocol/line.rb', line 35
def write_lines(*args)
if args.empty?
@stream.write(@eol)
else
args.each do |arg|
@stream.write(arg)
@stream.write(@eol)
end
end
@stream.flush
end
|