Class: Modal::ModalReadStream

Inherits:
Object
  • Object
show all
Defined in:
lib/modal/streams.rb

Instance Method Summary collapse

Constructor Details

#initialize(source_iterable) ⇒ ModalReadStream

Returns a new instance of ModalReadStream.



5
6
7
# File 'lib/modal/streams.rb', line 5

def initialize(source_iterable)
  @source_iterable = source_iterable
end

Instance Method Details

#closeObject



33
34
35
# File 'lib/modal/streams.rb', line 33

def close
  @source_iterable.close if @source_iterable.respond_to?(:close)
end

#each(&block) ⇒ Object



29
30
31
# File 'lib/modal/streams.rb', line 29

def each(&block)
  @source_iterable.each(&block)
end

#readObject



9
10
11
# File 'lib/modal/streams.rb', line 9

def read
  read_text
end

#read_bytesObject



21
22
23
24
25
26
27
# File 'lib/modal/streams.rb', line 21

def read_bytes
  chunks = []
  @source_iterable.each do |bytes|
    chunks << bytes.dup
  end
  chunks.join("").bytes.pack("C*")
end

#read_textObject



13
14
15
16
17
18
19
# File 'lib/modal/streams.rb', line 13

def read_text
  chunks = []
  @source_iterable.each do |bytes|
    chunks << bytes.dup.force_encoding("UTF-8")
  end
  chunks.join("")
end