Class: Browser::Device

Inherits:
Object
  • Object
show all
Defined in:
lib/browser/device.rb,
lib/browser/device/tv.rb,
lib/browser/device/psp.rb,
lib/browser/device/wii.rb,
lib/browser/device/base.rb,
lib/browser/device/ipad.rb,
lib/browser/device/wiiu.rb,
lib/browser/device/iphone.rb,
lib/browser/device/kindle.rb,
lib/browser/device/psvita.rb,
lib/browser/device/switch.rb,
lib/browser/device/android.rb,
lib/browser/device/samsung.rb,
lib/browser/device/surface.rb,
lib/browser/device/unknown.rb,
lib/browser/device/xbox_360.rb,
lib/browser/device/xbox_one.rb,
lib/browser/device/ipod_touch.rb,
lib/browser/device/kindle_fire.rb,
lib/browser/device/playstation3.rb,
lib/browser/device/playstation4.rb,
lib/browser/device/blackberry_playbook.rb

Defined Under Namespace

Classes: Android, Base, BlackBerryPlaybook, Ipad, Iphone, IpodTouch, Kindle, KindleFire, PSP, PSVita, PlayStation3, PlayStation4, Samsung, Surface, Switch, TV, Unknown, Wii, WiiU, Xbox360, XboxOne

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ua) ⇒ Device

Returns a new instance of Device.



56
57
58
# File 'lib/browser/device.rb', line 56

def initialize(ua)
  @ua = ua
end

Class Method Details

.matchersObject

Hold the list of device matchers. Order is important.



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/browser/device.rb', line 31

def self.matchers
  @matchers ||= [
    Samsung,
    XboxOne,
    Xbox360,
    Surface,
    TV,
    BlackBerryPlaybook,
    WiiU,
    Wii,
    Switch,
    KindleFire,
    Kindle,
    PlayStation4,
    PlayStation3,
    PSVita,
    PSP,
    Ipad,
    Iphone,
    IpodTouch,
    Android,
    Unknown
  ]
end

Instance Method Details

#blackberry_playbook?Boolean Also known as: playbook?

Returns:

  • (Boolean)


148
149
150
# File 'lib/browser/device.rb', line 148

def blackberry_playbook?
  id == :playbook
end

#console?Boolean

Detect if browser is console (currently Xbox, PlayStation, or Nintendo).

Returns:

  • (Boolean)


192
193
194
# File 'lib/browser/device.rb', line 192

def console?
  xbox? || playstation? || nintendo?
end

#idObject



66
67
68
# File 'lib/browser/device.rb', line 66

def id
  subject.id
end

#ipad?Boolean

Returns:

  • (Boolean)


88
89
90
# File 'lib/browser/device.rb', line 88

def ipad?
  id == :ipad
end

#iphone?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/browser/device.rb', line 101

def iphone?
  id == :iphone
end

#ipod_touch?Boolean Also known as: ipod?

Returns:

  • (Boolean)


96
97
98
# File 'lib/browser/device.rb', line 96

def ipod_touch?
  id == :ipod_touch
end

#kindle?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/browser/device.rb', line 125

def kindle?
  id == :kindle || kindle_fire?
end

#kindle_fire?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/browser/device.rb', line 129

def kindle_fire?
  id == :kindle_fire
end

#mobile?Boolean

Detect if browser is mobile.

Returns:

  • (Boolean)


84
85
86
# File 'lib/browser/device.rb', line 84

def mobile?
  detect_mobile? && !tablet?
end

#nameObject



70
71
72
# File 'lib/browser/device.rb', line 70

def name
  subject.name
end

#nintendo?Boolean

Detect if browser is Nintendo.

Returns:

  • (Boolean)


187
188
189
# File 'lib/browser/device.rb', line 187

def nintendo?
  wii? || wiiu? || switch?
end

#nintendo_switch?Boolean Also known as: switch?

Returns:

  • (Boolean)


143
144
145
# File 'lib/browser/device.rb', line 143

def nintendo_switch?
  id == :switch
end

#nintendo_wii?Boolean Also known as: wii?

Returns:

  • (Boolean)


133
134
135
# File 'lib/browser/device.rb', line 133

def nintendo_wii?
  id == :wii
end

#nintendo_wiiu?Boolean Also known as: wiiu?

Returns:

  • (Boolean)


138
139
140
# File 'lib/browser/device.rb', line 138

def nintendo_wiiu?
  id == :wiiu
end

#playstation?Boolean

Detect if browser is running under PlayStation.

Returns:

  • (Boolean)


182
183
184
# File 'lib/browser/device.rb', line 182

def playstation?
  ps3? || ps4?
end

#playstation_vita?Boolean Also known as: vita?, psp_vita?

Returns:

  • (Boolean)


119
120
121
# File 'lib/browser/device.rb', line 119

def playstation_vita?
  id == :psvita
end

#ps3?Boolean Also known as: playstation3?

Returns:

  • (Boolean)


105
106
107
# File 'lib/browser/device.rb', line 105

def ps3?
  id == :ps3
end

#ps4?Boolean Also known as: playstation4?

Returns:

  • (Boolean)


110
111
112
# File 'lib/browser/device.rb', line 110

def ps4?
  id == :ps4
end

#psp?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/browser/device.rb', line 115

def psp?
  id == :psp
end

#samsung?Boolean

Detect if device is a Samsung.

Returns:

  • (Boolean)


197
198
199
# File 'lib/browser/device.rb', line 197

def samsung?
  id == :samsung
end

#silk?Boolean

Detect if browser is Silk.

Returns:

  • (Boolean)


162
163
164
# File 'lib/browser/device.rb', line 162

def silk?
  ua.include?("Silk")
end

#surface?Boolean

Returns:

  • (Boolean)


153
154
155
# File 'lib/browser/device.rb', line 153

def surface?
  id == :surface
end

#tablet?Boolean

Detect if browser is tablet (currently iPad, Android, Surface or Playbook).

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/browser/device.rb', line 76

def tablet?
  ipad? ||
    (platform.android? && !detect_mobile?) ||
    surface? ||
    playbook?
end

#tv?Boolean

Returns:

  • (Boolean)


157
158
159
# File 'lib/browser/device.rb', line 157

def tv?
  id == :tv
end

#unknown?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/browser/device.rb', line 92

def unknown?
  id == :unknown_device
end

#xbox?Boolean

Detect if browser is running under Xbox.

Returns:

  • (Boolean)


167
168
169
# File 'lib/browser/device.rb', line 167

def xbox?
  ua.include?("Xbox")
end

#xbox_360?Boolean

Detect if browser is running under Xbox 360.

Returns:

  • (Boolean)


172
173
174
# File 'lib/browser/device.rb', line 172

def xbox_360?
  id == :xbox_360
end

#xbox_one?Boolean

Detect if browser is running under Xbox One.

Returns:

  • (Boolean)


177
178
179
# File 'lib/browser/device.rb', line 177

def xbox_one?
  id == :xbox_one
end