Class: Blur::Network::Channel

Inherits:
Object
  • Object
show all
Defined in:
library/blur/network/channel.rb

Overview

TODO:

make so that channels and users belongs to the network, and not like now where the user belongs to the channel, resulting in multiple user instances.

The Channel class is used for encapsulating a channel and its properties.

Users inside the channel is stored in the #channels attribute.

Modes can be set for a channel, but Blur is not ISupport-compliant yet.

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Channel) initialize(name, network = nil, users = [])

Instantiate a user with a nickname, a network and a user list.



33
34
35
36
37
38
39
40
# File 'library/blur/network/channel.rb', line 33

def initialize name, network = nil, users = []
  @name    = name
  @users   = users
  @modes   = ""
  @network = network

  users.each { |user| user.channel = self }
end

Instance Attribute Details

- (Encryption::Fish) encryption



27
28
29
# File 'library/blur/network/channel.rb', line 27

def encryption
  @encryption
end

- (String) modes



23
24
25
# File 'library/blur/network/channel.rb', line 23

def modes
  @modes
end

- (String) name



17
18
19
# File 'library/blur/network/channel.rb', line 17

def name
  @name
end

- (Network) network



25
26
27
# File 'library/blur/network/channel.rb', line 25

def network
  @network
end

- (String) topic



21
22
23
# File 'library/blur/network/channel.rb', line 21

def topic
  @topic
end

- (Array) users



19
20
21
# File 'library/blur/network/channel.rb', line 19

def users
  @users
end

Instance Method Details

- (Boolean) encrypted?

Check whether or not this is an encrypted channel.



30
# File 'library/blur/network/channel.rb', line 30

def encrypted?; not @encryption.nil? end

- (Object) inspect

Convert it to a debug-friendly format.



75
76
77
# File 'library/blur/network/channel.rb', line 75

def inspect
  %{#<#{self.class.name} @name=#{@name.inspect} @users=#{@users.inspect}}
end

- (Object) merge_modes(modes)

Merge the channels mode corresponding to the leading character (+ or -).



45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'library/blur/network/channel.rb', line 45

def merge_modes modes
  addition = true

  modes.each_char do |char|
    case char
    when ?+
      addition = true
    when ?-
      addition = false
    else
      addition ? @modes.concat(char) : @modes.delete!(char)
    end
  end
end

- (Object) say(message)

Send a message to the channel.



63
64
65
# File 'library/blur/network/channel.rb', line 63

def say message
  @network.say self, message
end

- (Object) to_s

Get the channels name.



86
87
88
# File 'library/blur/network/channel.rb', line 86

def to_s
  @name
end

- (Object) to_yaml(options = {})

Called when YAML attempts to save the object, which happens when a scripts cache contains this user and the script is unloaded.



81
82
83
# File 'library/blur/network/channel.rb', line 81

def to_yaml options = {}
  @name.to_yaml options
end

- (Object) user_by_nick(nick)

Find a user with nick as its nickname.



70
71
72
# File 'library/blur/network/channel.rb', line 70

def user_by_nick nick
  @users.find { |user| user.nick == nick }
end