Class: AirportEvents::Airport

Inherits:
Object
  • Object
show all
Defined in:
lib/airport_events/airport.rb

Constant Summary collapse

INFO_COMMAND =
"airport -I 2>&1"

Class Method Summary collapse

Class Method Details

.connected?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/airport_events/airport.rb', line 16

def self.connected?
  ssid.length > 0
end

.ensure_airport_command!Object



5
6
7
8
9
10
# File 'lib/airport_events/airport.rb', line 5

def self.ensure_airport_command!
  run_info_command
  unless $?.exitstatus == 0
    raise "Fatal: the 'airport' command is not in PATH. Run 'airport-log enable_airport' for instructions."
  end
end

.parse_ssid(result) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/airport_events/airport.rb', line 24

def self.parse_ssid result
  if result.match /\sSSID: /
    result[/\sSSID: (.*?)\n/, 1]
  else
    ""
  end
end

.run_info_commandObject



20
21
22
# File 'lib/airport_events/airport.rb', line 20

def self.run_info_command
  %x(#{INFO_COMMAND})
end

.ssidObject



12
13
14
# File 'lib/airport_events/airport.rb', line 12

def self.ssid
  parse_ssid(run_info_command)
end