Class: ParallelCalabash::AdbHelper

Inherits:
Object
  • Object
show all
Includes:
DevicesHelper
Defined in:
lib/parallel_calabash/adb_helper.rb

Instance Method Summary collapse

Methods included from DevicesHelper

#device_for_process, #number_of_connected_devices

Constructor Details

#initialize(filter = []) ⇒ AdbHelper

Returns a new instance of AdbHelper.



17
18
19
# File 'lib/parallel_calabash/adb_helper.rb', line 17

def initialize(filter = [])
  @filter = filter
end

Instance Method Details

#connected_devices_with_model_infoObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/parallel_calabash/adb_helper.rb', line 21

def connected_devices_with_model_info
  begin
    list =
        `adb devices -l`.split("\n").collect do |line|
          device = device_id_and_model(line)
          filter_device(device)
        end
    list.compact
  rescue
    []
  end
end

#device_id_and_model(line) ⇒ Object



34
35
36
37
38
# File 'lib/parallel_calabash/adb_helper.rb', line 34

def device_id_and_model line
  if line.match(/device(?!s)/)
    [line.split(" ").first, line.scan(/model:(.*) device/).flatten.first]
  end
end

#filter_device(device) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/parallel_calabash/adb_helper.rb', line 40

def filter_device device
  if @filter && !@filter.empty? && device
    device unless @filter.collect { |f| device[0].match(f) || device[1].match(f) }.compact.empty?
  else
    device
  end
end