Class: Bizside::UserAgent
- Inherits:
-
Object
- Object
- Bizside::UserAgent
show all
- Defined in:
- lib/bizside/user_agent.rb,
lib/bizside/user_agent/controller_helper.rb
Defined Under Namespace
Modules: ControllerHelper
Constant Summary
collapse
- USER_AGENTS =
[
ANDROID_MOBILE = 'android',
IPAD = 'ipad',
IPHONE = 'iphone',
PC = 'pc',
SMART_PHONE = 'sp',
]
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(name, http_user_agent = nil) ⇒ UserAgent
Returns a new instance of UserAgent.
25
26
27
28
29
|
# File 'lib/bizside/user_agent.rb', line 25
def initialize(name, http_user_agent = nil)
@name = name if USER_AGENTS.include?(name)
@name ||= PC
@http_user_agent = http_user_agent
end
|
Class Method Details
.parse(http_user_agent) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/bizside/user_agent.rb', line 12
def self.parse(http_user_agent)
case http_user_agent
when /Android.*Mobile/
new(ANDROID_MOBILE, http_user_agent)
when /iPhone/
new(IPHONE, http_user_agent)
when /iPad/
new(IPAD, http_user_agent)
else
new(PC, http_user_agent)
end
end
|
Instance Method Details
#actual ⇒ Object
35
36
37
|
# File 'lib/bizside/user_agent.rb', line 35
def actual
@actual ||= @http_user_agent ? self.class.parse(@http_user_agent) : self
end
|
#android_mobile? ⇒ Boolean
73
74
75
|
# File 'lib/bizside/user_agent.rb', line 73
def android_mobile?
self.name == ANDROID_MOBILE
end
|
#chrome? ⇒ Boolean
96
97
98
99
100
101
102
103
|
# File 'lib/bizside/user_agent.rb', line 96
def chrome?
case @http_user_agent
when /.* Chrome\/.*/
true
else
false
end
end
|
#ie? ⇒ Boolean
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/bizside/user_agent.rb', line 85
def ie?
case @http_user_agent
when /.* MSIE .* Windows .*/ true
when /.*Windows.*Trident.*/ true
else
false
end
end
|
#ipad? ⇒ Boolean
39
40
41
|
# File 'lib/bizside/user_agent.rb', line 39
def ipad?
self.name == IPAD
end
|
#iphone? ⇒ Boolean
69
70
71
|
# File 'lib/bizside/user_agent.rb', line 69
def iphone?
self.name == IPHONE
end
|
#mac? ⇒ Boolean
56
57
58
59
60
61
62
63
|
# File 'lib/bizside/user_agent.rb', line 56
def mac?
case @http_user_agent
when /.*Mac.*/
pc?
else
false
end
end
|
#name ⇒ Object
31
32
33
|
# File 'lib/bizside/user_agent.rb', line 31
def name
@name
end
|
#pc? ⇒ Boolean
43
44
45
|
# File 'lib/bizside/user_agent.rb', line 43
def pc?
self.name == PC
end
|
#priorities ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/bizside/user_agent.rb', line 77
def priorities
ret = []
ret << self.name
ret << SMART_PHONE if sp?
ret << PC unless pc?
ret
end
|
#sp? ⇒ Boolean
65
66
67
|
# File 'lib/bizside/user_agent.rb', line 65
def sp?
[ANDROID_MOBILE, IPHONE, SMART_PHONE].include?(self.name)
end
|
#windows? ⇒ Boolean
47
48
49
50
51
52
53
54
|
# File 'lib/bizside/user_agent.rb', line 47
def windows?
case @http_user_agent
when /.*Windows.*/
pc?
else
false
end
end
|