Class: Async::IO::Protocol::Line
- Inherits:
-
Object
- Object
- Async::IO::Protocol::Line
- Defined in:
- lib/async/io/protocol/line.rb
Instance Attribute Summary collapse
-
#eol ⇒ Object
readonly
Returns the value of attribute eol.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #each_line ⇒ Object
-
#initialize(stream, eol = $\) ⇒ Line
constructor
A new instance of Line.
- #peek_line ⇒ Object
- #read_line ⇒ Object
- #read_lines ⇒ Object
- #write_lines(*args) ⇒ Object
Constructor Details
#initialize(stream, eol = $\) ⇒ Line
Returns a new instance of Line.
27 28 29 30 |
# File 'lib/async/io/protocol/line.rb', line 27 def initialize(stream, eol = $\) @stream = stream @eol = eol end |
Instance Attribute Details
#eol ⇒ Object (readonly)
Returns the value of attribute eol.
33 34 35 |
# File 'lib/async/io/protocol/line.rb', line 33 def eol @eol end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
32 33 34 |
# File 'lib/async/io/protocol/line.rb', line 32 def stream @stream end |
Instance Method Details
#each_line ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/async/io/protocol/line.rb', line 60 def each_line return to_enum(:each_line) unless block_given? while line = @stream.read_until(@eol) yield line end end |
#peek_line ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/async/io/protocol/line.rb', line 50 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
46 47 48 |
# File 'lib/async/io/protocol/line.rb', line 46 def read_line @stream.read_until(@eol) or raise EOFError end |
#read_lines ⇒ Object
68 69 70 |
# File 'lib/async/io/protocol/line.rb', line 68 def read_lines @stream.read.split(@eol) end |
#write_lines(*args) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# 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 end |