Class: Ddig::Ip

Inherits:
Object
  • Object
show all
Defined in:
lib/ddig/ip.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(use_ipv4: nil, use_ipv6: nil) ⇒ Ip

Returns a new instance of Ip.



7
8
9
10
11
12
# File 'lib/ddig/ip.rb', line 7

def initialize(use_ipv4: nil, use_ipv6: nil)
  @use_ipv4 = use_ipv4
  @use_ipv6 = use_ipv6

  set_ip_type
end

Instance Attribute Details

#ip_typeObject (readonly)

Returns the value of attribute ip_type.



5
6
7
# File 'lib/ddig/ip.rb', line 5

def ip_type
  @ip_type
end

Class Method Details

.enable_ipv4?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/ddig/ip.rb', line 32

def self.enable_ipv4?
  ip_list.any? { |addr| addr.ipv4? }
end

.enable_ipv6?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/ddig/ip.rb', line 36

def self.enable_ipv6?
  ip_list.any? { |addr| addr.ipv6? }
end

Instance Method Details

#set_ip_typeObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ddig/ip.rb', line 14

def set_ip_type
  if @use_ipv4.nil? && self.class.enable_ipv4?
    @use_ipv4 = true
  end

  if @use_ipv6.nil? && self.class.enable_ipv6?
    @use_ipv6 = true
  end

  if @use_ipv4 && @use_ipv6
    @ip_type = :all
  elsif @use_ipv4
    @ip_type = :ipv4
  elsif @use_ipv6
    @ip_type = :ipv6
  end
end