Class: Ncrack::XML::Port

Inherits:
Object
  • Object
show all
Defined in:
lib/ncrack/xml/port.rb

Overview

Represents a port XML element.

Constant Summary collapse

PROTOCOLS =

Mapping of the protocol attribute values to Symbols.

{
  'tcp' => :tcp,
  'udp' => :udp
}

Instance Method Summary collapse

Constructor Details

#initialize(node) ⇒ Port

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initializes the port object.

Parameters:

  • node (Nokogiri::XML::Node)

    The XML node for the port XML element.



16
17
18
# File 'lib/ncrack/xml/port.rb', line 16

def initialize(node)
  @node = node
end

Instance Method Details

#nameString

The name associated with the port.

Returns:

  • (String)

    The value of the name attribute.



56
57
58
# File 'lib/ncrack/xml/port.rb', line 56

def name
  @name ||= @node['name']
end

#numberInteger

The port number.

Returns:

  • (Integer)

    The parsed value of the portid attribute.



46
47
48
# File 'lib/ncrack/xml/port.rb', line 46

def number
  @number ||= @node['portid'].to_i
end

#protocol:tcp, ...

The protocol of the port.

Returns:

  • (:tcp, :udp, String)

    The value of the protocol attribute.



32
33
34
35
36
37
38
# File 'lib/ncrack/xml/port.rb', line 32

def protocol
  @protocl ||= (
    protocol = @node['protocol']

    PROTOCOLS.fetch(protocol,protocol)
  )
end

#to_iInteger

Converts the port to an Integer.

Returns:

  • (Integer)

    Returns the #number.



66
67
68
# File 'lib/ncrack/xml/port.rb', line 66

def to_i
  number.to_i
end

#to_sString

Converts the port to a String.

Returns:

  • (String)

    Returns the #name.



76
77
78
# File 'lib/ncrack/xml/port.rb', line 76

def to_s
  name.to_s
end