Class: Calabash::Cucumber::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/calabash-cucumber/device.rb

Overview

Class device encapsulates information about the device or devices we are interacting with during a test. Credit: Due to jmoody's briar: github.com/jmoody/briar/blob/master/lib/briar/gestalt.rb

Constant Summary collapse

GESTALT_IPHONE =
'iPhone'
GESTALT_IPAD =
'iPad'
GESTALT_IPHONE5 =
'Retina 4-inch'
GESTALT_SIM_SYS =
'x86_64'
GESTALT_IPOD =
'iPod'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, version_data) ⇒ Device

Returns a new instance of Device.


26
27
28
29
30
31
32
33
34
# File 'lib/calabash-cucumber/device.rb', line 26

def initialize (endpoint, version_data)
  simulator_device = version_data['simulator_device']
  @endpoint = endpoint
  @system = version_data['system']
  @device_family = @system.eql?(GESTALT_SIM_SYS) ? simulator_device : @system.split(/[\d,.]/).first
  @simulator_details = version_data['simulator']
  @ios_version = version_data['iOS_version']
  @framework_version = version_data['version']
end

Instance Attribute Details

#device_familyObject (readonly)

Returns the value of attribute device_family


19
20
21
# File 'lib/calabash-cucumber/device.rb', line 19

def device_family
  @device_family
end

#endpointObject (readonly)

Returns the value of attribute endpoint


18
19
20
# File 'lib/calabash-cucumber/device.rb', line 18

def endpoint
  @endpoint
end

#framework_versionObject (readonly)

Returns the value of attribute framework_version


22
23
24
# File 'lib/calabash-cucumber/device.rb', line 22

def framework_version
  @framework_version
end

#ios_versionObject (readonly)

Returns the value of attribute ios_version


20
21
22
# File 'lib/calabash-cucumber/device.rb', line 20

def ios_version
  @ios_version
end

#simulator_detailsObject (readonly)

Returns the value of attribute simulator_details


20
21
22
# File 'lib/calabash-cucumber/device.rb', line 20

def simulator_details
  @simulator_details
end

#systemObject (readonly)

Returns the value of attribute system


21
22
23
# File 'lib/calabash-cucumber/device.rb', line 21

def system
  @system
end

#udidObject

Returns the value of attribute udid


24
25
26
# File 'lib/calabash-cucumber/device.rb', line 24

def udid
  @udid
end

Instance Method Details

#device?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/calabash-cucumber/device.rb', line 40

def device?
  not simulator?
end

#ios5?Boolean

Returns:

  • (Boolean)

79
80
81
# File 'lib/calabash-cucumber/device.rb', line 79

def ios5?
  ios_major_version.eql?('5')
end

#ios6?Boolean

Returns:

  • (Boolean)

75
76
77
# File 'lib/calabash-cucumber/device.rb', line 75

def ios6?
  ios_major_version.eql?('6')
end

#ios_major_versionObject


71
72
73
# File 'lib/calabash-cucumber/device.rb', line 71

def ios_major_version
  version_hash(ios_version)[:major_version]
end

#ipad?Boolean

Returns:

  • (Boolean)

52
53
54
# File 'lib/calabash-cucumber/device.rb', line 52

def ipad?
  device_family.eql? GESTALT_IPAD
end

#iphone?Boolean

Returns:

  • (Boolean)

44
45
46
# File 'lib/calabash-cucumber/device.rb', line 44

def iphone?
  device_family.eql? GESTALT_IPHONE
end

#iphone_5?Boolean

Returns:

  • (Boolean)

56
57
58
59
60
61
62
# File 'lib/calabash-cucumber/device.rb', line 56

def iphone_5?
  if simulator?
    simulator_details.split(/[(),]/)[3].eql? GESTALT_IPHONE5
  else
    system.split(/[\D]/).delete_if { |x| x.eql?('') }.first.eql?('5')
  end
end

#ipod?Boolean

Returns:

  • (Boolean)

48
49
50
# File 'lib/calabash-cucumber/device.rb', line 48

def ipod?
  device_family.eql? GESTALT_IPOD
end

#simulator?Boolean

Returns:

  • (Boolean)

36
37
38
# File 'lib/calabash-cucumber/device.rb', line 36

def simulator?
  system.eql?(GESTALT_SIM_SYS)
end

#version_hash(version_str) ⇒ Object


64
65
66
67
68
69
# File 'lib/calabash-cucumber/device.rb', line 64

def version_hash (version_str)
  tokens = version_str.split(/[,.]/)
  {:major_version => tokens[0],
   :minor_version => tokens[1],
   :bug_version => tokens[2]}
end