Class: IRC::Models::User

Inherits:
Object
  • Object
show all
Defined in:
lib/irc/models/user.rb

Direct Known Subclasses

Bot

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ User

Returns a new instance of User.

Raises:

  • (ArgumentError)


41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/irc/models/user.rb', line 41

def initialize(attributes)
  
  raise ArgumentError.new("Can't create a new user object. The :network attribute is missing.") if attributes[:network] == nil
  @network = attributes[:network]
  
  raise ArgumentError.new("Can't create a new user object. The :nick attribute is missing.") if attributes[:nick] == nil
  @nick = attributes[:nick].strip
  
  @login = attributes[:login]
  @hostname = attributes[:hostname]
  
  @channels = Hash.new
  
end

Instance Attribute Details

#hostnameObject

Returns the value of attribute hostname.



38
39
40
# File 'lib/irc/models/user.rb', line 38

def hostname
  @hostname
end

#loginObject

Returns the value of attribute login.



37
38
39
# File 'lib/irc/models/user.rb', line 37

def 
  @login
end

#networkObject (readonly)

Returns the value of attribute network.



34
35
36
# File 'lib/irc/models/user.rb', line 34

def network
  @network
end

#nickObject (readonly)

Returns the value of attribute nick.



35
36
37
# File 'lib/irc/models/user.rb', line 35

def nick
  @nick
end

#realnameObject

Returns the value of attribute realname.



39
40
41
# File 'lib/irc/models/user.rb', line 39

def realname
  @realname
end

Instance Method Details

#==(other) ⇒ Object



104
105
106
# File 'lib/irc/models/user.rb', line 104

def ==(other)
  return eql?(other)
end

#add_channel(channel) ⇒ Object



56
57
58
# File 'lib/irc/models/user.rb', line 56

def add_channel(channel)
  @channels[channel] = channel
end

#channelsObject



60
61
62
# File 'lib/irc/models/user.rb', line 60

def channels
  return @channels.values
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/irc/models/user.rb', line 64

def eql?(other)
  return (other.instance_of?(Bot) || other.instance_of?(User)) && network == other.network && nick == other.nick
end

#hashObject



68
69
70
# File 'lib/irc/models/user.rb', line 68

def hash
  return key.hash
end

#keyObject



72
73
74
# File 'lib/irc/models/user.rb', line 72

def key
  return "#{network.name.strip}|#{nick.strip}".downcase
end

#merge(other) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/irc/models/user.rb', line 76

def merge(other)
  
  @nick = other.nick
  
  self. = other.
  self.hostname = other.hostname
  
  other.channels.each do |other_channel|
    channel = network.lookup_or_create_channel(other_channel.name)
    add_channel(channel)
  end
  
end

#remove_channel(channel) ⇒ Object



90
91
92
# File 'lib/irc/models/user.rb', line 90

def remove_channel(channel)
  return @channels.delete(channel)
end

#to_sObject

Returns the nick name of the user.



95
96
97
# File 'lib/irc/models/user.rb', line 95

def to_s
  return @nick
end

#to_strObject

Returns the nick name of the user.



100
101
102
# File 'lib/irc/models/user.rb', line 100

def to_str
  return to_s
end