Class: Fourflusher::Simulator
- Inherits:
-
Object
- Object
- Fourflusher::Simulator
- Defined in:
- lib/fourflusher/find.rb
Overview
Metadata about an installed Xcode simulator
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#os_version ⇒ Object
readonly
Returns the value of attribute os_version.
Instance Method Summary collapse
- #compatible?(other_version) ⇒ Boolean
-
#device_and_model ⇒ Object
Returns the [device, model] for use during sorting Examples: [iPhone, 5s], [iPhone, 6s Plus], [Apple Watch Series 2, 38mm].
- #device_compare(my_device, other_device) ⇒ Object
- #os_name ⇒ Object
-
#sim_list_compare(other) ⇒ Object
Compare function for sorting simulators in order by - OS Name: ascending - OS Version: descending - Device type: iPhone first, then ascending - Model: ascending.
- #to_s ⇒ Object
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/fourflusher/find.rb', line 8 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/fourflusher/find.rb', line 9 def name @name end |
#os_version ⇒ Object (readonly)
Returns the value of attribute os_version.
10 11 12 |
# File 'lib/fourflusher/find.rb', line 10 def os_version @os_version end |
Instance Method Details
#compatible?(other_version) ⇒ Boolean
16 17 18 |
# File 'lib/fourflusher/find.rb', line 16 def compatible?(other_version) other_version <= os_version end |
#device_and_model ⇒ Object
Returns the [device, model] for use during sorting Examples: [iPhone, 5s], [iPhone, 6s Plus], [Apple Watch Series 2, 38mm]
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# 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) ⇒ Object
39 40 41 42 43 44 |
# 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 ⇒ Object
12 13 14 |
# File 'lib/fourflusher/find.rb', line 12 def os_name @os_name.downcase.to_sym end |
#sim_list_compare(other) ⇒ Object
Compare function for sorting simulators in order by
-
OS Name: ascending
-
OS Version: descending
-
Device type: iPhone first, then ascending
-
Model: ascending
29 30 31 32 33 34 35 36 37 |
# 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 ⇒ Object
20 21 22 |
# File 'lib/fourflusher/find.rb', line 20 def to_s "#{@name} (#{@id}) - #{@os_name} #{@os_version}" end |