Class: Vetinari::ChannelContainer
- Inherits:
-
Object
- Object
- Vetinari::ChannelContainer
- Includes:
- Celluloid
- Defined in:
- lib/vetinari/channel_container.rb
Instance Attribute Summary collapse
-
#channels ⇒ Object
readonly
Returns the value of attribute channels.
Instance Method Summary collapse
- #[](channel_or_channel_name) ⇒ Object
- #add(channel) ⇒ Object
-
#clear ⇒ Object
Removes all Channels from the ChannelList and returns them.
- #has_channel?(channel) ⇒ Boolean
-
#initialize ⇒ ChannelContainer
constructor
A new instance of ChannelContainer.
- #remove(channel) ⇒ Object
-
#remove_user(user) ⇒ Object
Removes a User from all Channels from the ChannelList.
-
#users ⇒ Object
Returns a Set of all Users that are in one of the Channels from the ChannelList.
Constructor Details
#initialize ⇒ ChannelContainer
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
#channels ⇒ Object (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 |
#clear ⇒ Object
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
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 |
#users ⇒ Object
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 |