Sha256: 07cc2b9877f7e02cfa72c04a05b6db5922adff52e409f3218f7d7947074f3faa

Contents?: true

Size: 1.85 KB

Versions: 1

Compression:

Stored size: 1.85 KB

Contents

#
# Copyright (c) 2006-2011 Hal Brodigan (postmodern.mod3 at gmail.com)
#
# This file is part of Ronin.
#
# Ronin is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ronin is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ronin.  If not, see <http://www.gnu.org/licenses/>.
#

require 'ronin/open_port'
require 'ronin/model'

module Ronin
  class Port

    include Model

    # Primary key of the port
    property :id, Serial

    # The protocol of the port (tcp/udp)
    property :protocol, String, :set => ['tcp', 'udp'],
                                :required => true,
                                :unique_index => :protocol_port

    # The port number
    property :number, Integer, :required => true,
                               :unique_index => :protocol_port

    # The open ports
    has 1..n, :open_ports

    validates_uniqueness_of :number, :scope => [:protocol]

    #
    # Converts the port to an integer.
    #
    # @return [Integer]
    #   The port number.
    #
    # @since 1.0.0
    #
    def to_i
      self.number.to_i
    end

    #
    # Converts the port to a string.
    #
    # @return [String]
    #   The port number and protocol.
    #
    # @since 1.0.0
    #
    def to_s
      "#{self.number}/#{self.protocol}"
    end

    #
    # Inspects the port.
    #
    # @return [String]
    #   The inspected port.
    #
    # @since 1.0.0
    #
    def inspect
      "#<#{self.class}: #{self}>"
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ronin-1.0.0.pre4 lib/ronin/port.rb