Class: Unified2::Protocol
- Inherits:
-
Object
- Object
- Unified2::Protocol
- Defined in:
- lib/unified2/protocol.rb
Overview
Protocol
Instance Method Summary collapse
-
#icmp? ⇒ true, false
ICMP?.
-
#initialize(protocol, packet = nil) ⇒ Protocol
constructor
Initialize protocol object.
-
#tcp? ⇒ true, false
TCP?.
-
#to_h ⇒ Hash
(also: #header)
Convert To Hash.
-
#to_s ⇒ String
Convert To String.
-
#udp? ⇒ true, false
UDP?.
Constructor Details
#initialize(protocol, packet = nil) ⇒ Protocol
Initialize protocol object
17 18 19 20 |
# File 'lib/unified2/protocol.rb', line 17 def initialize(protocol, packet=nil) @protocol = protocol @packet = packet end |
Instance Method Details
#icmp? ⇒ true, false
ICMP?
27 28 29 |
# File 'lib/unified2/protocol.rb', line 27 def icmp? @protocol == :ICMP end |
#tcp? ⇒ true, false
TCP?
36 37 38 |
# File 'lib/unified2/protocol.rb', line 36 def tcp? @protocol == :TCP end |
#to_h ⇒ Hash Also known as: header
Convert To Hash
69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/unified2/protocol.rb', line 69 def to_h hash = { :type => @protocol.to_s } if send(:"#{@protocol.downcase}?") hash.merge!(self.send(:"#{@protocol.downcase}")) end hash end |
#to_s ⇒ String
Convert To String
57 58 59 |
# File 'lib/unified2/protocol.rb', line 57 def to_s @protocol.to_s end |
#udp? ⇒ true, false
UDP?
45 46 47 |
# File 'lib/unified2/protocol.rb', line 45 def udp? @protocol == :UDP end |