Class: KDL::Types::IP

Inherits:
Value::Custom show all
Defined in:
lib/kdl/types/ip.rb

Direct Known Subclasses

IPV4, IPV6

Constant Summary

Constants inherited from Value

Value::Null

Instance Attribute Summary

Attributes inherited from Value::Custom

#oriinal_value

Attributes inherited from Value

#format, #type, #value

Class Method Summary collapse

Methods inherited from Value::Custom

#to_v1, #to_v2, #version

Methods inherited from Value

#==, #as_type, from, #initialize, #inspect, #method_missing, #respond_to_missing?, #stringify_value, #to_s, #to_v2, #version

Constructor Details

This class inherits a constructor from KDL::Value

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class KDL::Value

Class Method Details

.call(value, type = ip_type) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
13
# File 'lib/kdl/types/ip.rb', line 6

def self.call(value, type = ip_type)
  return nil unless value.is_a? ::KDL::Value::String

  ip = ::IPAddr.new(value.value)
  raise ArgumentError, "invalid #{ip_type} address" unless valid_ip?(ip)

  new(ip, type: type)
end

.valid_ip?(ip) ⇒ Boolean

Returns:



15
16
17
# File 'lib/kdl/types/ip.rb', line 15

def self.valid_ip?(ip)
  ip.__send__(:"#{ip_type}?")
end