Module: Rant::IOExtras::AbstractInputStream
- Includes:
- Enumerable, FakeIO
- Defined in:
- lib/rant/archive/rubyzip/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.
28 29 30 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 28 def lineno @lineno end |
Instance Method Details
#each_line(aSepString = $/) ⇒ Object Also known as: each
65 66 67 68 69 70 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 65 def each_line(aSepString = $/) while true yield readline(aSepString) end rescue EOFError end |
#flush ⇒ Object
53 54 55 56 57 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 53 def flush retVal=@outputBuffer @outputBuffer="" return retVal end |
#gets(aSepString = $/) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 36 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
22 23 24 25 26 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 22 def initialize super @lineno = 0 @outputBuffer = "" end |
#readline(aSepString = $/) ⇒ Object
59 60 61 62 63 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 59 def readline(aSepString = $/) retVal = gets(aSepString) raise EOFError if retVal == nil return retVal end |
#readlines(aSepString = $/) ⇒ Object
30 31 32 33 34 |
# File 'lib/rant/archive/rubyzip/ioextras.rb', line 30 def readlines(aSepString = $/) retVal = [] each_line(aSepString) { |line| retVal << line } return retVal end |