Class: IRC::Models::Packet

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes) ⇒ Packet

Returns a new instance of Packet.

Raises:

  • (ArgumentError)


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

def initialize(attributes)
  
  raise ArgumentError.new("Can't create a new packet. The :bot attribute is missing.") if attributes[:bot] == nil
  @bot = attributes[:bot]
  
  raise ArgumentError.new("Can't create a new packet. The :number attribute is missing.") if attributes[:number] == nil
  @number = attributes[:number]
  
  self.description = attributes[:description]
  self.size_in_bytes = attributes[:size_in_bytes]
  self.number_of_downloads = attributes[:number_of_downloads]   
  
end

Instance Attribute Details

#botObject (readonly)

Returns the value of attribute bot.



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

def bot
  @bot
end

#descriptionObject

Returns the value of attribute description.



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

def description
  @description
end

#numberObject (readonly)

Returns the value of attribute number.



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

def number
  @number
end

#number_of_downloadsObject

Returns the value of attribute number_of_downloads.



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

def number_of_downloads
  @number_of_downloads
end

#size_in_bytesObject

Returns the value of attribute size_in_bytes.



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

def size_in_bytes
  @size_in_bytes
end

Instance Method Details

#==(other) ⇒ Object



63
64
65
# File 'lib/irc/models/packet.rb', line 63

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

#eql?(other) ⇒ Boolean

Returns true if the other Packet object is equal to the current.

Returns:

  • (Boolean)


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

def eql?(other)
  return other.instance_of?(Packet) && bot == other.bot && number == other.number && description == other.description
end

#hashObject



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

def hash
  return key.hash
end

#keyObject



76
77
78
# File 'lib/irc/models/packet.rb', line 76

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

#merge(other) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/irc/models/packet.rb', line 55

def merge(other)
  #      @bot = other.bot
  @number = other.number
  self.description = other.description
  self.size_in_bytes = other.size_in_bytes
  self.number_of_downloads = other.number_of_downloads
end