Class: Copper::DataTypes::IPAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/copper/data_types/ip_addr.rb

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ IPAddress

Returns a new instance of IPAddress.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/copper/data_types/ip_addr.rb', line 7

def initialize(value)
	if value.is_a? ::String
		@value = ::IPAddress.parse(value)
	elsif value.is_a?(::IPAddress::IPv4)
		@value = value
	elsif value.is_a?(::IPAddress::IPv6)
		@value = value
	else
		raise ::Copper::RuntimeError, "cannot convert #{value} to IPAddress"
	end
rescue ArgumentError => exc
	raise ::Copper::RuntimeError, exc.message
end

Instance Method Details

#addressObject



45
46
47
# File 'lib/copper/data_types/ip_addr.rb', line 45

def address
	@value.address
end

#firstObject



21
22
23
# File 'lib/copper/data_types/ip_addr.rb', line 21

def first
	@value.first
end

#full_addressObject



41
42
43
# File 'lib/copper/data_types/ip_addr.rb', line 41

def full_address
	@value.to_string
end

#in(value) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/copper/data_types/ip_addr.rb', line 29

def in(value)
	if value.is_a?(::Copper::DataTypes::IPAddress)
		to_check = value.ip_address
	elsif value.is_a?(::IPAddress)
		to_check = value
	else
		raise ::Copper::RuntimeError, "#{value} is not an IP address"
	end

	(@value.first.to_i <= to_check.to_i) && (@value.last.to_i >= to_check.to_i)
end

#ip_addressObject



85
86
87
# File 'lib/copper/data_types/ip_addr.rb', line 85

def ip_address
	@value
end

#is_class_aObject



73
74
75
# File 'lib/copper/data_types/ip_addr.rb', line 73

def is_class_a
	@value.a?
end

#is_class_bObject



77
78
79
# File 'lib/copper/data_types/ip_addr.rb', line 77

def is_class_b
	@value.b?
end

#is_class_cObject



81
82
83
# File 'lib/copper/data_types/ip_addr.rb', line 81

def is_class_c
	@value.c?
end

#is_loopbackObject



65
66
67
# File 'lib/copper/data_types/ip_addr.rb', line 65

def is_loopback
	@value.loopback?
end

#is_multicastObject



69
70
71
# File 'lib/copper/data_types/ip_addr.rb', line 69

def is_multicast
	@value.multicast?
end

#is_networkObject



61
62
63
# File 'lib/copper/data_types/ip_addr.rb', line 61

def is_network
	@value.network?
end

#lastObject



25
26
27
# File 'lib/copper/data_types/ip_addr.rb', line 25

def last
	@value.last
end

#netmaskObject



49
50
51
# File 'lib/copper/data_types/ip_addr.rb', line 49

def netmask
	@value.netmask
end

#octetsObject



53
54
55
# File 'lib/copper/data_types/ip_addr.rb', line 53

def octets
	@value.octets
end

#prefixObject



57
58
59
# File 'lib/copper/data_types/ip_addr.rb', line 57

def prefix
	@value.prefix.to_i
end

#to_sObject



89
90
91
# File 'lib/copper/data_types/ip_addr.rb', line 89

def to_s
	@value.to_string
end