Sha256: f01d075327b5a297ac5c843ceb679c08b8a892f00067b3532125998639536386

Contents?: true

Size: 1.01 KB

Versions: 4

Compression:

Stored size: 1.01 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.downcase }
  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

4 entries across 4 versions & 1 rubygems

Version Path
wpa_cli_web-0.0.17 lib/wpa_cli_web/access_point_list.rb
wpa_cli_web-0.0.15 lib/wpa_cli_web/access_point_list.rb
wpa_cli_web-0.0.14 lib/wpa_cli_web/access_point_list.rb
wpa_cli_web-0.0.13 lib/wpa_cli_web/access_point_list.rb