Class: Vetinari::ChannelContainer

Inherits:
Object
  • Object
show all
Includes:
Celluloid
Defined in:
lib/vetinari/channel_container.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeChannelContainer

Returns a new instance of ChannelContainer.



9
10
11
# File 'lib/vetinari/channel_container.rb', line 9

def initialize
  @channels = Set.new
end

Instance Attribute Details

#channelsObject (readonly)

Returns the value of attribute channels.



5
6
7
# File 'lib/vetinari/channel_container.rb', line 5

def channels
  @channels
end

Instance Method Details

#[](channel_or_channel_name) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vetinari/channel_container.rb', line 17

def [](channel_or_channel_name)
  case channel_or_channel_name
  when Channel
    if @channels.include?(channel_or_channel_name)
      channel_or_channel_name
    end
  when String
    @channels.find do |c|
      c.name.downcase == channel_or_channel_name.downcase
    end
  end
end

#add(channel) ⇒ Object



13
14
15
# File 'lib/vetinari/channel_container.rb', line 13

def add(channel)
  @channels << channel
end

#clearObject

Removes all Channels from the ChannelList and returns them.



55
56
57
58
59
# File 'lib/vetinari/channel_container.rb', line 55

def clear
  channels = @channels.dup
  @channels.clear
  channels
end

#has_channel?(channel) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/vetinari/channel_container.rb', line 30

def has_channel?(channel)
  self[channel] ? true : false
end

#remove(channel) ⇒ Object



34
35
36
37
38
# File 'lib/vetinari/channel_container.rb', line 34

def remove(channel)
  if has_channel?(channel)
    @channels.delete(channel)
  end
end

#remove_user(user) ⇒ Object

Removes a User from all Channels from the ChannelList. Returning a Set of Channels in which the User was.



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/vetinari/channel_container.rb', line 42

def remove_user(user)
  channels = Set.new

  @channels.each do |channel|
    if channel.remove_user(user)
      channels << channel
    end
  end

  channels
end

#usersObject

Returns a Set of all Users that are in one of the Channels from the ChannelList. TODO: Refactor



64
65
66
67
68
69
70
71
72
# File 'lib/vetinari/channel_container.rb', line 64

def users
  users = Set.new

  @channels.each do |channel|
    users.merge(channel.users)
  end

  users
end