Class: IRC::Models::User
- Inherits:
-
Object
- Object
- IRC::Models::User
- Defined in:
- lib/irc/models/user.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hostname ⇒ Object
Returns the value of attribute hostname.
-
#login ⇒ Object
Returns the value of attribute login.
-
#network ⇒ Object
readonly
Returns the value of attribute network.
-
#nick ⇒ Object
readonly
Returns the value of attribute nick.
-
#realname ⇒ Object
Returns the value of attribute realname.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #add_channel(channel) ⇒ Object
- #channels ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(attributes) ⇒ User
constructor
A new instance of User.
- #key ⇒ Object
- #merge(other) ⇒ Object
- #remove_channel(channel) ⇒ Object
-
#to_s ⇒ Object
Returns the nick name of the user.
-
#to_str ⇒ Object
Returns the nick name of the user.
Constructor Details
#initialize(attributes) ⇒ User
Returns a new instance of User.
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
#hostname ⇒ Object
Returns the value of attribute hostname.
38 39 40 |
# File 'lib/irc/models/user.rb', line 38 def hostname @hostname end |
#login ⇒ Object
Returns the value of attribute login.
37 38 39 |
# File 'lib/irc/models/user.rb', line 37 def login @login end |
#network ⇒ Object (readonly)
Returns the value of attribute network.
34 35 36 |
# File 'lib/irc/models/user.rb', line 34 def network @network end |
#nick ⇒ Object (readonly)
Returns the value of attribute nick.
35 36 37 |
# File 'lib/irc/models/user.rb', line 35 def nick @nick end |
#realname ⇒ Object
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 |
#channels ⇒ Object
60 61 62 |
# File 'lib/irc/models/user.rb', line 60 def channels return @channels.values end |
#eql?(other) ⇒ 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 |
#hash ⇒ Object
68 69 70 |
# File 'lib/irc/models/user.rb', line 68 def hash return key.hash end |
#key ⇒ Object
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.login = other.login 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_s ⇒ Object
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_str ⇒ Object
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 |