-
Notifications
You must be signed in to change notification settings - Fork 2
/
questions.rb
112 lines (87 loc) · 2.8 KB
/
questions.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
module Browserino
module Core
module Questions
SOCIAL_MEDIA = [:facebook, :fb, :twitter, :linkedin,
:instagram, :pinterest, :tumblr].freeze
SEARCH_ENGINES = [:google, :bing, :yahoo_slurp,
:baiduspider, :duckduckgo, :ddg].freeze
BROWSERS = (Core::PATTERNS[:browser].keys + [:ff]).freeze
CONSOLES = [:xbox, :playstation, :nintendo_ds, :wii].freeze
OPERATING_SYSTEMS = (Browserino::Mapping
.constants(:true)
.map(&:downcase) + [:osx, :bb, :win]).freeze
def compat?
invertable ie? && browser_version != browser_version(compat: true)
end
def known?
invertable !browser_name.nil? || !bot_name.nil?
end
def mobile?
invertable !ua.match(Core::PATTERNS[:operating_system][:mobile]).nil?
end
def x64?
invertable system_architecture == 'x64'
end
def x32?
invertable system_architecture == 'x32'
end
def osx?(*arg)
macintosh?(*arg)
end
def win?(*arg)
windows?(*arg)
end
def bb?(*arg)
blackberry?(*arg)
end
def fb?(*arg)
facebook?(*arg)
end
def ff?(*arg)
firefox?(*arg)
end
def ddg?(*arg)
duckduckgo?(*arg)
end
def playstation?
invertable console_name == 'playstation'
end
def nintendo_ds?
invertable console_name == 'nintendo_ds'
end
def xbox?
invertable console_name == 'xbox'
end
def wii?
invertable console_name == 'wii'
end
def bot?(name = nil)
is_bot = ua.strip.empty? || !bot_name.nil?
is_name = name.nil? || name.to_s.downcase.tr('_', ' ') == bot_name
invertable is_bot && is_name
end
def console?(name = nil)
arg = (name.nil? ? console_name : name).to_s.to_sym
invertable CONSOLES.include?(arg)
end
def search_engine?(name = nil)
arg = (name.nil? ? search_engine_name : name).to_s.to_sym
invertable SEARCH_ENGINES.include?(arg)
end
def social_media?(name = nil)
arg = (name.nil? ? bot_name : name).to_s.to_sym
invertable SOCIAL_MEDIA.include?(arg.to_s.to_sym)
end
def platform?(name = nil, opts = {})
arg = (name.nil? ? system_name : name).to_s.to_sym
invertable OPERATING_SYSTEMS.include?(arg) &&
(opts[:version].nil? ? true : send("#{name}?", opts[:version]))
end
def browser?(name = nil, opts = {})
arg = (name.nil? ? browser_name.tr(' ', '_') : name).to_s.to_sym
invertable BROWSERS.include?(arg) &&
(opts[:version].nil? ? true : send("#{name}?", opts[:version]))
end
end
end
end