Sha256: d7fb0f02ec64031c811ba516b9ca07520cd2bbc0266757961044f303a3ca766d

Contents?: true

Size: 1 KB

Versions: 3

Compression:

Stored size: 1 KB

Contents

class AccessPointList
  include WpaCliRuby

  # Initialize with scan results. This assumes that cli_client.scan()
  # has been called elsewhere. When this application is run with the
  # wifi interface in AP mode, calling scan() is destructive.
  def initialize(cli_client = WpaCli.new)
    @access_points = cli_client.scan_results
  end

  def access_points
    strongest_unique_ssids_sorted_alphabetically
  end

  def strongest_unique_ssids_sorted_alphabetically
    strongest_unique_ssids.
      sort_by { |network| network.ssid }
  end

  def strongest_unique_ssids
    network_groups.
      map {|network_group| network_group.sort_by { |network| network.signal_level}.reverse.take(1)}.
      flatten
  end

  def network_groups
    access_points_grouped_by_ssid.map {|ssid, network_group| network_group}
  end

  def access_points_grouped_by_ssid
    access_points_with_an_ssid.group_by {|network| network.ssid}
  end

  def access_points_with_an_ssid
    @access_points.reject { |network| network.ssid.nil? }
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
wpa_cli_web-0.0.12 lib/wpa_cli_web/access_point_list.rb
wpa_cli_web-0.0.11 lib/wpa_cli_web/access_point_list.rb
wpa_cli_web-0.0.10 lib/wpa_cli_web/access_point_list.rb