Class: Blur::User

Inherits:
Object
  • Object
show all
Defined in:
library/blur/user.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 User class is used for encapsulating a user and its properties.

The user owns a reference to its parent channel.

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nick, network = nil) ⇒ User

Instantiate a user with a nickname.



39
40
41
42
43
44
45
46
47
48
49
# File 'library/blur/user.rb', line 39

def initialize nick, network = nil
  @nick  = nick
  @modes = String.new
  @channels = []
  @network = network
  
  if modes = prefix_to_mode(nick[0])
    @nick  = nick[1..-1]
    @modes = modes
  end
end

Instance Attribute Details

#channelsObject

Returns the value of attribute channels.



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

def channels
  @channels
end

#hostString

Returns the users hostname.

Returns:

  • (String)

    the users hostname.



20
21
22
# File 'library/blur/user.rb', line 20

def host
  @host
end

#modesString

Returns all the modes set on the user.

Returns:

  • (String)

    all the modes set on the user.



22
23
24
# File 'library/blur/user.rb', line 22

def modes
  @modes
end

#nameString

Returns the users username.

Returns:

  • (String)

    the users username.



18
19
20
# File 'library/blur/user.rb', line 18

def name
  @name
end

#networkNetwork

Returns a reference to the network.

Returns:

  • (Network)

    a reference to the network.



24
25
26
# File 'library/blur/user.rb', line 24

def network
  @network
end

#nickString

Returns the users nickname.

Returns:

  • (String)

    the users nickname.



16
17
18
# File 'library/blur/user.rb', line 16

def nick
  @nick
end

Instance Method Details

#admin?Boolean

Check to see if the user is an admin (+a)

Returns:

  • (Boolean)


28
# File 'library/blur/user.rb', line 28

def admin?; @modes.include? "a" end

#half_operator?Boolean

Check to see if the user is an half-operator (+h)

Returns:

  • (Boolean)


36
# File 'library/blur/user.rb', line 36

def half_operator?; @modes.include? "h" end

#inspectObject

Convert it to a debug-friendly format.



77
78
79
# File 'library/blur/user.rb', line 77

def inspect
  %{#<#{self.class.name}:0x#{self.object_id.to_s 16} @nick=#{@nick.inspect}>}
end

#merge_modes(modes) ⇒ Object

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

Parameters:

  • modes (String)

    the modes to merge with.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'library/blur/user.rb', line 54

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

#operator?Boolean

Check to see if the user is an operator (+o)

Returns:

  • (Boolean)


34
# File 'library/blur/user.rb', line 34

def operator?; @modes.include? "o" end

#owner?Boolean

Check to see if the user is the owner (+q)

Returns:

  • (Boolean)


32
# File 'library/blur/user.rb', line 32

def owner?; @modes.include? "q" end

#say(message) ⇒ Object

Send a private message to the user.

Parameters:

  • message (String)

    the message to send.



72
73
74
# File 'library/blur/user.rb', line 72

def say message
  @network.say self, message
end

#to_sObject

Get the users nickname.



88
89
90
# File 'library/blur/user.rb', line 88

def to_s
  @nick
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.



83
84
85
# File 'library/blur/user.rb', line 83

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

#voice?Boolean

Check to see if the user has voice (+v)

Returns:

  • (Boolean)


30
# File 'library/blur/user.rb', line 30

def voice?; @modes.include? "v" end