Class: GData::HTTP::MimeBodyString
- Inherits:
-
Object
- Object
- GData::HTTP::MimeBodyString
- Defined in:
- lib/gdata/http/mime_body.rb
Overview
Class makes a string into a stream-like object
Instance Method Summary collapse
-
#initialize(source_string) ⇒ MimeBodyString
constructor
A new instance of MimeBodyString.
-
#read(bytes_requested) ⇒ Object
Implement read so that this class can be treated as a stream.
- #rewind ⇒ Object
Constructor Details
#initialize(source_string) ⇒ MimeBodyString
Returns a new instance of MimeBodyString.
82 83 84 85 |
# File 'lib/gdata/http/mime_body.rb', line 82 def initialize(source_string) @string = source_string @bytes_read = 0 end |
Instance Method Details
#read(bytes_requested) ⇒ Object
Implement read so that this class can be treated as a stream.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/gdata/http/mime_body.rb', line 92 def read(bytes_requested) if @bytes_read == @string.length return false elsif bytes_requested > @string.length - @bytes_read bytes_requested = @string.length - @bytes_read end buffer = @string[@bytes_read, bytes_requested] @bytes_read += bytes_requested return buffer end |
#rewind ⇒ Object
87 88 89 |
# File 'lib/gdata/http/mime_body.rb', line 87 def rewind @bytes_read = 0 end |