Class: Ip

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-powerdns/includes/Ip.class.rb

Overview

Copyright © 2013 Matthias Kadenbach github.com/mattes/vagrant-dnsmasq

Constant Summary collapse

MATCH_IP4 =
/^(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[0-9]{1,2})){3}$/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ipv4) ⇒ Ip

Returns a new instance of Ip.

Raises:

  • (ArgumentError)


8
9
10
11
12
13
14
15
16
17
# File 'lib/vagrant-powerdns/includes/Ip.class.rb', line 8

def initialize(ipv4)

  if ipv4.is_a? Ip
    ipv4 = ipv4.v4
  end

  raise ArgumentError, "IPv4 '#{ipv4}' must match #{MATCH_IP4}" unless Ip::ipv4_valid?(ipv4)

  @ipv4 = ipv4
end

Class Method Details

.ipv4_valid?(ipv4) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/vagrant-powerdns/includes/Ip.class.rb', line 19

def self.ipv4_valid?(ipv4)
  if not ipv4.blank? and Ip::MATCH_IP4.match(ipv4) then true else false end
end

Instance Method Details

#to_sObject



27
28
29
# File 'lib/vagrant-powerdns/includes/Ip.class.rb', line 27

def to_s
  v4
end

#v4Object



23
24
25
# File 'lib/vagrant-powerdns/includes/Ip.class.rb', line 23

def v4
  @ipv4
end