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

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

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

#encryptionEncryption::Fish



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

def encryption
  @encryption
end

#modesString



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

def modes
  @modes
end

#nameString



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

def name
  @name
end

#networkNetwork



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

def network
  @network
end

#topicString



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

def topic
  @topic
end

#usersArray



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

def users
  @users
end

Instance Method Details

#encrypted?Boolean

Check whether or not this is an encrypted channel.



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

def encrypted?; not @encryption.nil? end

#inspectObject

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

#merge_modes(modes) ⇒ Object

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

#say(message) ⇒ Object

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

#to_sObject

Get the channels name.



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

def to_s
  @name
end

#to_yaml(options = {}) ⇒ Object

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

#user_by_nick(nick) ⇒ Object

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