class Fourflusher::Simulator

Metadata about an installed Xcode simulator

Attributes

id[R]
name[R]
os_version[R]

Public Class Methods

new(device_json, os_name, os_version) click to toggle source
# File lib/fourflusher/find.rb, line 67
def initialize(device_json, os_name, os_version)
  @id = device_json['udid']
  @name = device_json['name']
  @os_name = os_name
  @os_version = Gem::Version.new os_version
end

Public Instance Methods

compatible?(other_version) click to toggle source
# File lib/fourflusher/find.rb, line 16
def compatible?(other_version)
  other_version <= os_version
end
device_and_model() click to toggle source

Returns the [device, model] for use during sorting Examples: [iPhone, 5s], [iPhone, 6s Plus], [Apple Watch Series 2, 38mm]

# File lib/fourflusher/find.rb, line 48
def device_and_model
  if os_name == :watchos
    # Sample string: Apple Watch Series 2 - 38mm
    name.split ' - '
  else
    # Sample string: "iPhone 5s" or "iPhone 6 Plus" or "iPad Air 2"
    if name.start_with? 'Apple TV'
      # The last part is the model, and the rest is the device
      parts = name.rpartition(' ').reject { |str| str.strip.empty? }
      [parts[0...-1].join(' '), parts.drop(parts.count - 1).join(' ')].map(&:strip)
    else
      # The first part is device, and the rest is the model
      name.split ' ', 2
    end
  end
end
device_compare(my_device, other_device) click to toggle source
# File lib/fourflusher/find.rb, line 39
def device_compare(my_device, other_device)
  return -1 if my_device == 'iPhone'
  return 1 if other_device == 'iPhone'
  return my_device <=> other_device unless my_device.nil? || other_device.nil?
  other_device.nil? ? 1 : -1
end
os_name() click to toggle source
# File lib/fourflusher/find.rb, line 12
def os_name
  @os_name.downcase.to_sym
end
sim_list_compare(other) click to toggle source

Compare function for sorting simulators in order by

  • OS Name: ascending

  • OS Version: descending

  • Device type: iPhone first, then ascending

  • Model: ascending

# File lib/fourflusher/find.rb, line 29
def sim_list_compare(other)
  return os_name.to_s <=> other.os_name.to_s unless os_name == other.os_name
  return other.os_version <=> os_version unless os_version == other.os_version
  device1, model1 = device_and_model
  device2, model2 = other.device_and_model
  return device_compare(device1, device2) unless device1 == device2
  return model1 <=> model2 unless model1.nil? || model2.nil?
  model2.nil? ? 1 : -1
end
to_s() click to toggle source
# File lib/fourflusher/find.rb, line 20
def to_s
  "#{@name} (#{@id}) - #{@os_name} #{@os_version}"
end