Class: Browser::Device
- Inherits:
-
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/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: Base, BlackBerryPlaybook, Ipad, Iphone, IpodTouch, Kindle, KindleFire, PSP, PSVita, PlayStation3, PlayStation4, Surface, TV, Unknown, Wii, WiiU, Xbox360, XboxOne
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(ua) ⇒ Device
Returns a new instance of Device.
30
31
32
|
# File 'lib/browser/device.rb', line 30
def initialize(ua)
@ua = ua
end
|
Instance Attribute Details
#ua ⇒ Object
Returns the value of attribute ua.
4
5
6
|
# File 'lib/browser/device.rb', line 4
def ua
@ua
end
|
Class Method Details
.matchers ⇒ Object
Hold the list of device matchers. Order is important.
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/browser/device.rb', line 8
def self.matchers
@matchers ||= [
XboxOne,
Xbox360,
Surface,
TV,
BlackBerryPlaybook,
WiiU,
Wii,
KindleFire,
Kindle,
PlayStation4,
PlayStation3,
PSVita,
PSP,
Iphone,
Ipad,
IpodTouch,
Unknown
]
end
|
Instance Method Details
#blackberry_playbook? ⇒ Boolean
Also known as:
playbook?
118
119
120
|
# File 'lib/browser/device.rb', line 118
def blackberry_playbook?
id == :playbook
end
|
#console? ⇒ Boolean
Detect if browser is console (currently Xbox, PlayStation, or Nintendo).
162
163
164
|
# File 'lib/browser/device.rb', line 162
def console?
xbox? || playstation? || nintendo?
end
|
#id ⇒ Object
40
41
42
|
# File 'lib/browser/device.rb', line 40
def id
subject.id
end
|
#ipad? ⇒ Boolean
62
63
64
|
# File 'lib/browser/device.rb', line 62
def ipad?
id == :ipad
end
|
#iphone? ⇒ Boolean
75
76
77
|
# File 'lib/browser/device.rb', line 75
def iphone?
id == :iphone
end
|
#ipod_touch? ⇒ Boolean
Also known as:
ipod?
70
71
72
|
# File 'lib/browser/device.rb', line 70
def ipod_touch?
id == :ipod_touch
end
|
#kindle? ⇒ Boolean
100
101
102
|
# File 'lib/browser/device.rb', line 100
def kindle?
id == :kindle || kindle_fire?
end
|
#kindle_fire? ⇒ Boolean
104
105
106
|
# File 'lib/browser/device.rb', line 104
def kindle_fire?
id == :kindle_fire
end
|
#mobile? ⇒ Boolean
Detect if browser is mobile.
58
59
60
|
# File 'lib/browser/device.rb', line 58
def mobile?
detect_mobile? && !tablet?
end
|
#name ⇒ Object
44
45
46
|
# File 'lib/browser/device.rb', line 44
def name
subject.name
end
|
#nintendo? ⇒ Boolean
Detect if browser is Nintendo.
157
158
159
|
# File 'lib/browser/device.rb', line 157
def nintendo?
wii? || wiiu?
end
|
#nintendo_wii? ⇒ Boolean
Also known as:
wii?
108
109
110
|
# File 'lib/browser/device.rb', line 108
def nintendo_wii?
id == :wii
end
|
#nintendo_wiiu? ⇒ Boolean
Also known as:
wiiu?
113
114
115
|
# File 'lib/browser/device.rb', line 113
def nintendo_wiiu?
id == :wiiu
end
|
#playstation? ⇒ Boolean
Detect if browser is running under PlayStation.
152
153
154
|
# File 'lib/browser/device.rb', line 152
def playstation?
ps3? || ps4?
end
|
#playstation_vita? ⇒ Boolean
Also known as:
vita?, psp_vita?
94
95
96
|
# File 'lib/browser/device.rb', line 94
def playstation_vita?
id == :psvita
end
|
#ps3? ⇒ Boolean
Also known as:
playstation3?
79
80
81
|
# File 'lib/browser/device.rb', line 79
def ps3?
id == :ps3
end
|
#ps4? ⇒ Boolean
Also known as:
playstation4?
84
85
86
|
# File 'lib/browser/device.rb', line 84
def ps4?
id == :ps4
end
|
#psp? ⇒ Boolean
90
91
92
|
# File 'lib/browser/device.rb', line 90
def psp?
id == :psp
end
|
#silk? ⇒ Boolean
Detect if browser is Silk.
132
133
134
|
# File 'lib/browser/device.rb', line 132
def silk?
ua =~ /Silk/
end
|
#subject ⇒ Object
34
35
36
37
38
|
# File 'lib/browser/device.rb', line 34
def subject
@subject ||= self.class.matchers
.map {|matcher| matcher.new(ua) }
.find(&:match?)
end
|
#surface? ⇒ Boolean
123
124
125
|
# File 'lib/browser/device.rb', line 123
def surface?
id == :surface
end
|
#tablet? ⇒ Boolean
Detect if browser is tablet (currently iPad, Android, Surface or Playbook).
50
51
52
53
54
55
|
# File 'lib/browser/device.rb', line 50
def tablet?
ipad? ||
(platform.android? && !detect_mobile?) ||
surface? ||
playbook?
end
|
#tv? ⇒ Boolean
127
128
129
|
# File 'lib/browser/device.rb', line 127
def tv?
id == :tv
end
|
#unknown? ⇒ Boolean
66
67
68
|
# File 'lib/browser/device.rb', line 66
def unknown?
id == :unknown
end
|
#xbox? ⇒ Boolean
Detect if browser is running under Xbox.
137
138
139
|
# File 'lib/browser/device.rb', line 137
def xbox?
ua =~ /Xbox/
end
|
#xbox_360? ⇒ Boolean
Detect if browser is running under Xbox 360.
142
143
144
|
# File 'lib/browser/device.rb', line 142
def xbox_360?
id == :xbox_360
end
|
#xbox_one? ⇒ Boolean
Detect if browser is running under Xbox One.
147
148
149
|
# File 'lib/browser/device.rb', line 147
def xbox_one?
id == :xbox_one
end
|