Class: MacOS::HardwarePort

Inherits:
Object
  • Object
show all
Defined in:
lib/MacOS/HardwarePort.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hardware_port: nil, device: nil, ethernet_address: nil) ⇒ HardwarePort

Returns a new instance of HardwarePort.



82
83
84
85
86
# File 'lib/MacOS/HardwarePort.rb', line 82

def initialize(hardware_port: nil, device: nil, ethernet_address: nil)
  @hardware_port = hardware_port
  @device = device
  @ethernet_address = ethernet_address
end

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



79
80
81
# File 'lib/MacOS/HardwarePort.rb', line 79

def device
  @device
end

#ethernet_addressObject

Returns the value of attribute ethernet_address.



80
81
82
# File 'lib/MacOS/HardwarePort.rb', line 80

def ethernet_address
  @ethernet_address
end

#hardware_portObject

class << self



78
79
80
# File 'lib/MacOS/HardwarePort.rb', line 78

def hardware_port
  @hardware_port
end

Class Method Details

.find_by_interface(interface) ⇒ Object Also known as: find_by_device



55
56
57
# File 'lib/MacOS/HardwarePort.rb', line 55

def find_by_interface(interface)
  all.detect{|hardware_port| hardware_port.interface == interface}
end

.find_by_mac_address(mac_address) ⇒ Object Also known as: find_by_ethernet_address



65
66
67
# File 'lib/MacOS/HardwarePort.rb', line 65

def find_by_mac_address(mac_address)
  all.detect{|hardware_port| hardware_port.ethernet_address == mac_address}
end

.find_by_name(name) ⇒ Object Also known as: find_by_hardware_port



60
61
62
# File 'lib/MacOS/HardwarePort.rb', line 60

def find_by_name(name)
  all.detect{|hardware_port| hardware_port.name == name}
end

.parse(output = nil) ⇒ Object Also known as: all, hardware_ports, ports



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/MacOS/HardwarePort.rb', line 31

def parse(output = nil)
  output ||= self.output
  hardware_ports = []
  hardware_port = nil
  output.each_line do |line|
    # p line
    if line == "\n" || line == ""
      hardware_ports << hardware_port if hardware_port
      hardware_port = new
    else
      label, value = line.captures(/^(.+): (.+)/)
      case label
      when 'Hardware Port'; hardware_port.hardware_port = value
      when 'Device'; hardware_port.device = value
      when 'Ethernet Address'; hardware_port.ethernet_address = value
      end
    end
  end
  hardware_ports
end

Instance Method Details

#interfaceObject



96
97
98
# File 'lib/MacOS/HardwarePort.rb', line 96

def interface
  @device
end

#mac_addressObject



92
93
94
# File 'lib/MacOS/HardwarePort.rb', line 92

def mac_address
  @ethernet_address
end

#nameObject



88
89
90
# File 'lib/MacOS/HardwarePort.rb', line 88

def name
  @hardware_port
end