Class: OSX::HardwarePort

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deviceObject

Returns the value of attribute device.



50
51
52
# File 'lib/OSX/HardwarePort.rb', line 50

def device
  @device
end

#ethernet_addressObject

Returns the value of attribute ethernet_address.



51
52
53
# File 'lib/OSX/HardwarePort.rb', line 51

def ethernet_address
  @ethernet_address
end

#hardware_portObject

class << self



49
50
51
# File 'lib/OSX/HardwarePort.rb', line 49

def hardware_port
  @hardware_port
end

Class Method Details

.allObject



33
34
35
# File 'lib/OSX/HardwarePort.rb', line 33

def all
  parse(output)
end

.find_by_device(device) ⇒ Object



37
38
39
# File 'lib/OSX/HardwarePort.rb', line 37

def find_by_device(device)
  all.detect{|hardware_port| hardware_port.device == device}
end

.parse(output) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/OSX/HardwarePort.rb', line 14

def parse(output)
  hardware_ports = []
  hardware_port = nil
  output.each_line do |line|
    if line == "\n" || line == ""
      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
    hardware_ports << hardware_port
  end
  hardware_ports
end

Instance Method Details

#nameObject



59
60
61
# File 'lib/OSX/HardwarePort.rb', line 59

def name
  @hardware_port
end

#new(hardware_port:, device:, ethernet_address:) ⇒ Object



53
54
55
56
57
# File 'lib/OSX/HardwarePort.rb', line 53

def new(hardware_port:, device:, ethernet_address:)
  @hardware_port = hardware_port
  @device = device
  @ethernet_address = ethernet_address
end