Module: IOExtras::AbstractInputStream
- Includes:
- Enumerable, FakeIO
- Included in:
- Zip::NullInputStream, Zip::ZipInputStream
- Defined in:
- lib/zip/ioextras.rb
Overview
Implements many of the convenience methods of IO such as gets, getc, readline and readlines depends on: input_finished?, produce_input and read
Instance Attribute Summary collapse
-
#lineno ⇒ Object
Returns the value of attribute lineno.
Instance Method Summary collapse
- #each_line(aSepString = $/) ⇒ Object (also: #each)
- #flush ⇒ Object
- #gets(aSepString = $/) ⇒ Object
- #initialize ⇒ Object
- #readline(aSepString = $/) ⇒ Object
- #readlines(aSepString = $/) ⇒ Object
Methods included from FakeIO
Methods included from Enumerable
Instance Attribute Details
#lineno ⇒ Object
Returns the value of attribute lineno.
23 24 25 |
# File 'lib/zip/ioextras.rb', line 23 def lineno @lineno end |
Instance Method Details
#each_line(aSepString = $/) ⇒ Object Also known as: each
60 61 62 63 64 65 |
# File 'lib/zip/ioextras.rb', line 60 def each_line(aSepString = $/) while true yield readline(aSepString) end rescue EOFError end |
#flush ⇒ Object
48 49 50 51 52 |
# File 'lib/zip/ioextras.rb', line 48 def flush retVal=@outputBuffer @outputBuffer="" return retVal end |
#gets(aSepString = $/) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/zip/ioextras.rb', line 31 def gets(aSepString=$/) @lineno = @lineno.next return read if aSepString == nil aSepString="#{$/}#{$/}" if aSepString == "" bufferIndex=0 while ((matchIndex = @outputBuffer.index(aSepString, bufferIndex)) == nil) bufferIndex=@outputBuffer.length if input_finished? return @outputBuffer.empty? ? nil : flush end @outputBuffer << produce_input end sepIndex=matchIndex + aSepString.length return @outputBuffer.slice!(0...sepIndex) end |
#initialize ⇒ Object
17 18 19 20 21 |
# File 'lib/zip/ioextras.rb', line 17 def initialize super @lineno = 0 @outputBuffer = "" end |
#readline(aSepString = $/) ⇒ Object
54 55 56 57 58 |
# File 'lib/zip/ioextras.rb', line 54 def readline(aSepString = $/) retVal = gets(aSepString) raise EOFError if retVal == nil return retVal end |
#readlines(aSepString = $/) ⇒ Object
25 26 27 28 29 |
# File 'lib/zip/ioextras.rb', line 25 def readlines(aSepString = $/) retVal = [] each_line(aSepString) { |line| retVal << line } return retVal end |