Sha256: 343b1901858ba61cd54dda108aaa43c1beb93679eb94579b007a39927562d3a6

Contents?: true

Size: 602 Bytes

Versions: 4

Compression:

Stored size: 602 Bytes

Contents

# frozen_string_literal: true
require 'socket'
require 'ipaddr'

module Steam
  # Access to the Local IP
  #
  # @example Get Local IP
  #   ip = LocalIp.new
  #   ip.to_s # => '192.168.1.158'
  #   ip.to_i # => 3232235934
  class LocalIp
    def initialize
      @addr = Socket.ip_address_list.detect(&:ipv4_private?)
    end

    # Get the IP address as a string
    #
    # @return [String] the ip
    def to_s
      @addr.ip_address
    end
    alias address to_s

    # Get the IP address as a int
    #
    # @return [Integer] the ip
    def to_i
      IPAddr.new(address).to_i
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
steamrb-0.1.3 lib/steam/local_ip.rb
steamrb-0.1.2 lib/steam/local_ip.rb
steamrb-0.1.1 lib/steam/local_ip.rb
steamrb-0.1.0 lib/steam/local_ip.rb