Parent

Validator::IpAddress

Public Class Methods

new(value) click to toggle source
# File lib/validator/ip_address.rb, line 5
def initialize(value)
  @value = value
end

Public Instance Methods

has_prefix?() click to toggle source

check if ip has prefix

# File lib/validator/ip_address.rb, line 10
def has_prefix?
  @value =~ /\//
end
is_ipv4?() click to toggle source

IPv4 determination by . (dot)

# File lib/validator/ip_address.rb, line 27
def is_ipv4?
  @value =~ /\./
end
valid?() click to toggle source
# File lib/validator/ip_address.rb, line 47
def valid?
  valid_ipv4? || valid_ipv6?
end
valid_ipv4?() click to toggle source
# File lib/validator/ip_address.rb, line 39
def valid_ipv4?
  IPAddress(@value).ipv4? rescue false
end
valid_ipv4_prefix?() click to toggle source

IPv4 addresses which are only 32 bits long

# File lib/validator/ip_address.rb, line 15
def valid_ipv4_prefix?
  prefix = get_prefix
  (prefix >= 1 and prefix <= 32)
end
valid_ipv6?() click to toggle source
# File lib/validator/ip_address.rb, line 43
def valid_ipv6?
  IPAddress(@value).ipv6? rescue false
end
valid_ipv6_prefix?() click to toggle source

IPv6 addresses are 128 bits long

# File lib/validator/ip_address.rb, line 21
def valid_ipv6_prefix?
  prefix = get_prefix
  (prefix >= 1 and prefix <= 128)
end
valid_prefix?() click to toggle source
# File lib/validator/ip_address.rb, line 31
def valid_prefix?
  if is_ipv4?
    valid_ipv4_prefix?
  else
    valid_ipv6_prefix?
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.