Class: Entropy::Stream

Inherits:
Object
  • Object
show all
Defined in:
lib/entropy/stream.rb

Overview

Class used to define a stream inside the space

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStream

Returns a new instance of Stream.



8
9
10
# File 'lib/entropy/stream.rb', line 8

def initialize
  @streams = Hash.new
end

Instance Attribute Details

#streamsObject (readonly)

Returns the value of attribute streams.



6
7
8
# File 'lib/entropy/stream.rb', line 6

def streams
  @streams
end

Instance Method Details

#add_stream(stream) ⇒ Object

Adds a stream (a File or a String) to the space



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/entropy/stream.rb', line 13

def add_stream(stream)
  iter = nil 
  if stream.respond_to?("binmode?")
    if stream.binmode?
      puts "Binary File Stream Initialization..."
      iter = :each_byte
    else
      puts "Char File Stream Initialization..."
      iter = :each_char
    end
  elsif  stream.respond_to?("each_char")
    puts "Char Stream Initialization..."
    iter = :each_char
  elsif  stream.respond_to?("each_byte")
    puts "Binary Stream Initialization..."
    iter = :each_byte
  else
    raise "Wrong type of stream"
  end
  @streams[stream] = iter
end