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.

Constant Summary collapse

GESTALT_IPHONE =
'iPhone'
GESTALT_IPAD =
'iPad'
GESTALT_IPHONE5 =
'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.



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

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']
  @iphone_app_emulated_on_ipad = version_data['iphone_app_emulated_on_ipad']
end

Instance Attribute Details

#device_familyObject (readonly)

Returns the value of attribute device_family.



16
17
18
# File 'lib/calabash-cucumber/device.rb', line 16

def device_family
  @device_family
end

#endpointObject (readonly)

Returns the value of attribute endpoint.



15
16
17
# File 'lib/calabash-cucumber/device.rb', line 15

def endpoint
  @endpoint
end

#framework_versionObject (readonly)

Returns the value of attribute framework_version.



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

def framework_version
  @framework_version
end

#ios_versionObject (readonly)

Returns the value of attribute ios_version.



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

def ios_version
  @ios_version
end

#iphone_app_emulated_on_ipadObject (readonly)

Returns the value of attribute iphone_app_emulated_on_ipad.



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

def iphone_app_emulated_on_ipad
  @iphone_app_emulated_on_ipad
end

#simulator_detailsObject (readonly)

Returns the value of attribute simulator_details.



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

def simulator_details
  @simulator_details
end

#systemObject (readonly)

Returns the value of attribute system.



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

def system
  @system
end

#udidObject

Returns the value of attribute udid.



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

def udid
  @udid
end

Instance Method Details

#device?Boolean

Returns:

  • (Boolean)


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

def device?
  not simulator?
end

#ios5?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/calabash-cucumber/device.rb', line 82

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

#ios6?Boolean

Returns:

  • (Boolean)


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

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

#ios7?Boolean

Returns:

  • (Boolean)


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

def ios7?
  ios_major_version.eql?('7')
end

#ios_major_versionObject



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

def ios_major_version
  version_hash(ios_version)[:major_version]
end

#ipad?Boolean

Returns:

  • (Boolean)


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

def ipad?
  device_family.eql? GESTALT_IPAD
end

#iphone?Boolean

Returns:

  • (Boolean)


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

def iphone?
  device_family.eql? GESTALT_IPHONE
end

#iphone_5?Boolean

Returns:

  • (Boolean)


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

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

#iphone_app_emulated_on_ipad?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/calabash-cucumber/device.rb', line 92

def iphone_app_emulated_on_ipad?
  iphone_app_emulated_on_ipad
end

#ipod?Boolean

Returns:

  • (Boolean)


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

def ipod?
  device_family.eql? GESTALT_IPOD
end

#screen_sizeObject



86
87
88
89
90
# File 'lib/calabash-cucumber/device.rb', line 86

def screen_size
  return { :width => 768, :height => 1024 } if ipad?
  return { :width => 320, :height => 568 } if iphone_5?
  { :width => 320, :height => 480 }
end

#simulator?Boolean

Returns:

  • (Boolean)


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

def simulator?
  system.eql?(GESTALT_SIM_SYS)
end

#version_hash(version_str) ⇒ Object



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

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