Class: Ddig::Ip
- Inherits:
-
Object
- Object
- Ddig::Ip
- Defined in:
- lib/ddig/ip.rb
Instance Attribute Summary collapse
-
#ip_type ⇒ Object
readonly
Returns the value of attribute ip_type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(use_ipv4: nil, use_ipv6: nil) ⇒ Ip
constructor
A new instance of Ip.
- #set_ip_type ⇒ Object
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_type ⇒ Object (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
32 33 34 |
# File 'lib/ddig/ip.rb', line 32 def self.enable_ipv4? ip_list.any? { |addr| addr.ipv4? } end |
.enable_ipv6? ⇒ 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_type ⇒ Object
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 |