Class: Seahorse::StringIO
- Inherits:
-
Object
- Object
- Seahorse::StringIO
- Defined in:
- lib/seahorse/stringio.rb
Instance Method Summary collapse
- #eof ⇒ Object (also: #eof?)
-
#initialize(data = '') ⇒ StringIO
constructor
A new instance of StringIO.
- #read(bytes = nil, output_buffer = nil) ⇒ Object
- #rewind ⇒ Object
- #size ⇒ Object
- #truncate(bytes) ⇒ Object
- #write(data) ⇒ Object
Constructor Details
#initialize(data = '') ⇒ StringIO
Returns a new instance of StringIO.
3 4 5 6 |
# File 'lib/seahorse/stringio.rb', line 3 def initialize(data = '') @data = data @offset = 0 end |
Instance Method Details
#eof ⇒ Object Also known as: eof?
36 37 38 |
# File 'lib/seahorse/stringio.rb', line 36 def eof @offset == @data.bytesize end |
#read(bytes = nil, output_buffer = nil) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/seahorse/stringio.rb', line 14 def read(bytes = nil, output_buffer = nil) if bytes data = partial_read(bytes) else data = full_read end output_buffer ? output_buffer.replace(data || '') : data end |
#rewind ⇒ Object
23 24 25 |
# File 'lib/seahorse/stringio.rb', line 23 def rewind @offset = 0 end |
#size ⇒ Object
32 33 34 |
# File 'lib/seahorse/stringio.rb', line 32 def size @data.bytesize end |
#truncate(bytes) ⇒ Object
27 28 29 30 |
# File 'lib/seahorse/stringio.rb', line 27 def truncate(bytes) @data = @data[0,bytes] bytes end |
#write(data) ⇒ Object
8 9 10 11 12 |
# File 'lib/seahorse/stringio.rb', line 8 def write(data) @data << data @offset += data.bytesize data.bytesize end |