class Chizuru::Provider

Represents a tweets provider.

Provider takes tweets from Source and provides them to Consumer.

Public Class Methods

new() click to toggle source

Initializes an instance of Provider and starts the loop.

# File lib/chizuru/provider.rb, line 9
def initialize
  @consumers = []
  @queue = Queue.new
  Thread.new do
    while (true)
      data = @queue.deq
      dispatch(data)
    end
  end
end

Public Instance Methods

add_consumer(cons) click to toggle source

Adds a consumer.

# File lib/chizuru/provider.rb, line 21
def add_consumer(cons)
  @consumers << cons
end
dispatch(data) click to toggle source

Dispatches the status to the consumers this has.

# File lib/chizuru/provider.rb, line 36
def dispatch(data)
  @consumers.each do |consumer|
    Thread.new do
      consumer.receive(data)
    end
  end
end
receive(data) click to toggle source

On receiving a status from the source.

# File lib/chizuru/provider.rb, line 31
def receive(data)
  @queue.enq data
end
remove_consumer(cons) click to toggle source

Removes a consumer.

# File lib/chizuru/provider.rb, line 26
def remove_consumer(cons)
  @consumers.delete(cons)
end