Class: KDL::Types::IP

Inherits:
Value
  • Object
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

#format, #type, #value

Class Method Summary collapse

Methods inherited from Value

#as_type, from, #initialize, #stringify_value, #to_s

Constructor Details

This class inherits a constructor from KDL::Value

Class Method Details

.call(value, type = ip_type) ⇒ Object

Raises:

  • (ArgumentError)


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

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:



13
14
15
# File 'lib/kdl/types/ip.rb', line 13

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