Class: Butler::IRC::ChannelList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/butler/irc/channellist.rb

Overview

Butler::IRC::Channel represents a channel in IRC.

Instance Method Summary collapse

Methods included from Enumerable

#join

Constructor Details

#initialize(client) ⇒ ChannelList

Returns a new instance of ChannelList.



37
38
39
40
41
42
# File 'lib/butler/irc/channellist.rb', line 37

def initialize(client)
	@all		= {}
	@client = client
	@users  = nil
	@lock   = Mutex.new
end

Instance Method Details

#[](channel) ⇒ Object

Get the channel with name ‘channel’



91
92
93
# File 'lib/butler/irc/channellist.rb', line 91

def [](channel)
	@all[channel.to_str.downcase]
end

#channel_namesObject

returns the lowercased channelnames



69
70
71
# File 'lib/butler/irc/channellist.rb', line 69

def channel_names
	@all.keys
end

#create(channel, *args) ⇒ Object

Will return the single instance representing the channel with name ‘channel’.



51
52
53
54
55
56
# File 'lib/butler/irc/channellist.rb', line 51

def create(channel, *args)
	@lock.synchronize {
		channel	= self[channel] || Channel.new(@users, channel, *args)
		@all[channel.to_str]	= channel
	}
end

#delete(channel) ⇒ Object

Remove a channel from the channels-list



81
82
83
# File 'lib/butler/irc/channellist.rb', line 81

def delete(channel)
	@all.delete(channel.to_str.downcase)
end

#delete_user(user, reason) ⇒ Object

Remove user from all channels



86
87
88
# File 'lib/butler/irc/channellist.rb', line 86

def delete_user(user, reason) #:nodoc:
	@all.each_value { |channel| channel.delete_user(user, reason) }
end

#each(&block) ⇒ Object

Iterates through all known channels (@all)



59
60
61
# File 'lib/butler/irc/channellist.rb', line 59

def each(&block)
	@all.each_value(&block)
end

#lengthObject

returns channelcount



64
65
66
# File 'lib/butler/irc/channellist.rb', line 64

def length
	@all.length
end

#map_names(*names) ⇒ Object

returns all channels with that name (names should be normalized to lowercased name)



76
77
78
# File 'lib/butler/irc/channellist.rb', line 76

def map_names(*names)
	@all.values_at(*names)
end

#users=(users) ⇒ Object



44
45
46
47
# File 'lib/butler/irc/channellist.rb', line 44

def users=(users)
	raise "Can't set @users twice" if @users
	@users = users
end