Class: Modal::ModalWriteStream
- Inherits:
-
Object
- Object
- Modal::ModalWriteStream
- Defined in:
- lib/modal/streams.rb
Instance Method Summary collapse
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(sink_writable) ⇒ ModalWriteStream
constructor
A new instance of ModalWriteStream.
- #write(data) ⇒ Object
- #write_bytes(bytes) ⇒ Object
- #write_text(text) ⇒ Object
Constructor Details
#initialize(sink_writable) ⇒ ModalWriteStream
Returns a new instance of ModalWriteStream.
39 40 41 |
# File 'lib/modal/streams.rb', line 39 def initialize(sink_writable) @sink_writable = sink_writable end |
Instance Method Details
#close ⇒ Object
64 65 66 |
# File 'lib/modal/streams.rb', line 64 def close @sink_writable.close if @sink_writable.respond_to?(:close) end |
#flush ⇒ Object
68 69 70 |
# File 'lib/modal/streams.rb', line 68 def flush @sink_writable.flush if @sink_writable.respond_to?(:flush) end |
#write(data) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/modal/streams.rb', line 43 def write(data) if data.is_a?(String) if data.encoding == Encoding::BINARY write_bytes(data) else write_text(data) end else write_bytes(data.to_s) end end |
#write_bytes(bytes) ⇒ Object
60 61 62 |
# File 'lib/modal/streams.rb', line 60 def write_bytes(bytes) @sink_writable.write(bytes) end |
#write_text(text) ⇒ Object
56 57 58 |
# File 'lib/modal/streams.rb', line 56 def write_text(text) @sink_writable.write(text) end |