Class: MsgBuffer

Inherits:
Object
  • Object
show all
Defined in:
lib/monitor/server/msg_buffer.rb

Instance Method Summary collapse

Constructor Details

#initialize(size) ⇒ MsgBuffer

Returns a new instance of MsgBuffer.



14
15
16
17
# File 'lib/monitor/server/msg_buffer.rb', line 14

def initialize(size)
  @buff = Array.new()
  @size=size
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/monitor/server/msg_buffer.rb', line 36

def empty?
 return  nitems_local(@buff) == 0
end

#full?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/monitor/server/msg_buffer.rb', line 32

def full?
  nitems_local(@buff) >= @size
end

#getObject



24
25
26
# File 'lib/monitor/server/msg_buffer.rb', line 24

def get()
  return @buff.pop
end

#has_more?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/monitor/server/msg_buffer.rb', line 28

def has_more?
  nitems_local(@buff) != 0
end

#nitems_local(arr) ⇒ Object

nitems method does not exist anymore in ruby 1.9.3



4
5
6
7
8
9
10
11
12
# File 'lib/monitor/server/msg_buffer.rb', line 4

def nitems_local(arr)
  cpt = 0
  arr.each {|val|
    if val
       cpt+=1
    end
  }
  return cpt
end

#put(msg) ⇒ Object



19
20
21
22
# File 'lib/monitor/server/msg_buffer.rb', line 19

def put(msg)
  @buff.unshift(msg)
  #puts "message put nitems=" + nitems_local(@buff).to_s
end