Class: Copper::DataTypes::IPAddress
- Inherits:
-
Object
- Object
- Copper::DataTypes::IPAddress
- Defined in:
- lib/copper/data_types/ip_addr.rb
Instance Method Summary collapse
- #address ⇒ Object
- #first ⇒ Object
- #full_address ⇒ Object
- #in(value) ⇒ Object
-
#initialize(value) ⇒ IPAddress
constructor
A new instance of IPAddress.
- #ip_address ⇒ Object
- #is_class_a ⇒ Object
- #is_class_b ⇒ Object
- #is_class_c ⇒ Object
- #is_loopback ⇒ Object
- #is_multicast ⇒ Object
- #is_network ⇒ Object
- #last ⇒ Object
- #netmask ⇒ Object
- #octets ⇒ Object
- #prefix ⇒ Object
- #to_s ⇒ Object
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. end |
Instance Method Details
#address ⇒ Object
45 46 47 |
# File 'lib/copper/data_types/ip_addr.rb', line 45 def address @value.address end |
#first ⇒ Object
21 22 23 |
# File 'lib/copper/data_types/ip_addr.rb', line 21 def first @value.first end |
#full_address ⇒ Object
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_address ⇒ Object
85 86 87 |
# File 'lib/copper/data_types/ip_addr.rb', line 85 def ip_address @value end |
#is_class_a ⇒ Object
73 74 75 |
# File 'lib/copper/data_types/ip_addr.rb', line 73 def is_class_a @value.a? end |
#is_class_b ⇒ Object
77 78 79 |
# File 'lib/copper/data_types/ip_addr.rb', line 77 def is_class_b @value.b? end |
#is_class_c ⇒ Object
81 82 83 |
# File 'lib/copper/data_types/ip_addr.rb', line 81 def is_class_c @value.c? end |
#is_loopback ⇒ Object
65 66 67 |
# File 'lib/copper/data_types/ip_addr.rb', line 65 def is_loopback @value.loopback? end |
#is_multicast ⇒ Object
69 70 71 |
# File 'lib/copper/data_types/ip_addr.rb', line 69 def is_multicast @value.multicast? end |
#is_network ⇒ Object
61 62 63 |
# File 'lib/copper/data_types/ip_addr.rb', line 61 def is_network @value.network? end |
#last ⇒ Object
25 26 27 |
# File 'lib/copper/data_types/ip_addr.rb', line 25 def last @value.last end |
#netmask ⇒ Object
49 50 51 |
# File 'lib/copper/data_types/ip_addr.rb', line 49 def netmask @value.netmask end |
#octets ⇒ Object
53 54 55 |
# File 'lib/copper/data_types/ip_addr.rb', line 53 def octets @value.octets end |
#prefix ⇒ Object
57 58 59 |
# File 'lib/copper/data_types/ip_addr.rb', line 57 def prefix @value.prefix.to_i end |
#to_s ⇒ Object
89 90 91 |
# File 'lib/copper/data_types/ip_addr.rb', line 89 def to_s @value.to_string end |