Class: Ifconf::Parsers::Ipv4Line
- Inherits:
-
Object
- Object
- Ifconf::Parsers::Ipv4Line
- Defined in:
- lib/ifconf/parsers/ipv4_line.rb
Overview
Frozen value object wrapping a single inet line from an ifconfig block. Extracts the IPv4 address, netmask, CIDR prefix, and optional broadcast.
Constant Summary collapse
- INET_PATTERN =
/\binet\b(?!6)/- INET_ADDRESS_PATTERN =
/\binet\s+(\S+)/- NETMASK_PATTERN =
/\bnetmask\s+(\S+)/- BROADCAST_PATTERN =
/\bbroadcast\s+(\S+)/
Instance Attribute Summary collapse
-
#address ⇒ Object
readonly
Returns the value of attribute address.
-
#broadcast ⇒ Object
readonly
Returns the value of attribute broadcast.
-
#netmask ⇒ Object
readonly
Returns the value of attribute netmask.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(line) ⇒ Ipv4Line
constructor
A new instance of Ipv4Line.
Constructor Details
#initialize(line) ⇒ Ipv4Line
Returns a new instance of Ipv4Line.
13 14 15 16 17 18 19 |
# File 'lib/ifconf/parsers/ipv4_line.rb', line 13 def initialize(line) @address = extract_address(line) @netmask = extract_netmask(line) @prefix = MaskConverter.to_prefix(@netmask) @broadcast = extract_broadcast(line) freeze end |
Instance Attribute Details
#address ⇒ Object (readonly)
Returns the value of attribute address.
11 12 13 |
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11 def address @address end |
#broadcast ⇒ Object (readonly)
Returns the value of attribute broadcast.
11 12 13 |
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11 def broadcast @broadcast end |
#netmask ⇒ Object (readonly)
Returns the value of attribute netmask.
11 12 13 |
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11 def netmask @netmask end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
11 12 13 |
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11 def prefix @prefix end |