Class: Ifconf::Parsers::Ipv4Line

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#addressObject (readonly)

Returns the value of attribute address.



11
12
13
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11

def address
  @address
end

#broadcastObject (readonly)

Returns the value of attribute broadcast.



11
12
13
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11

def broadcast
  @broadcast
end

#netmaskObject (readonly)

Returns the value of attribute netmask.



11
12
13
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11

def netmask
  @netmask
end

#prefixObject (readonly)

Returns the value of attribute prefix.



11
12
13
# File 'lib/ifconf/parsers/ipv4_line.rb', line 11

def prefix
  @prefix
end