useragent 0.4.9 → 0.4.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +19 -1
- data/lib/user_agent/browsers/all.rb +15 -0
- metadata +4 -4
data/README.rdoc
CHANGED
@@ -2,8 +2,26 @@
|
|
2
2
|
|
3
3
|
UserAgent is a Ruby library that parses and compares HTTP User Agents.
|
4
4
|
|
5
|
+
=== Installation
|
5
6
|
|
6
|
-
|
7
|
+
gem install useragent
|
8
|
+
|
9
|
+
=== Examples
|
10
|
+
|
11
|
+
==== Reporting
|
12
|
+
|
13
|
+
string = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.56 Safari/536.5'
|
14
|
+
user_agent = UserAgent.parse(string)
|
15
|
+
user_agent.browser
|
16
|
+
# => 'Chrome'
|
17
|
+
user_agent.version
|
18
|
+
# => '19.0.1084.56'
|
19
|
+
user_agent.platform
|
20
|
+
# => 'Macintosh'
|
21
|
+
user_agent.mobile?
|
22
|
+
# => false
|
23
|
+
|
24
|
+
==== Comparison
|
7
25
|
|
8
26
|
Browser = Struct.new(:browser, :version)
|
9
27
|
SupportedBrowsers = [
|
@@ -71,6 +71,21 @@ class UserAgent
|
|
71
71
|
end
|
72
72
|
end
|
73
73
|
|
74
|
+
def bot?
|
75
|
+
# Match common case when bots refer to themselves as bots in
|
76
|
+
# the application comment. There are no standards for how bots
|
77
|
+
# should call themselves so its not an exhaustive method.
|
78
|
+
#
|
79
|
+
# If you want to expand the scope, override the method and
|
80
|
+
# provide your own regexp. Any patches to future extend this
|
81
|
+
# list will be rejected.
|
82
|
+
if comment = application.comment
|
83
|
+
comment.any? { |c| c =~ /bot/i }
|
84
|
+
else
|
85
|
+
false
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
74
89
|
private
|
75
90
|
def detect_product(product)
|
76
91
|
detect { |useragent| useragent.product.to_s.downcase == product.to_s.downcase }
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: useragent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 4
|
9
|
-
-
|
10
|
-
version: 0.4.
|
9
|
+
- 10
|
10
|
+
version: 0.4.10
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Peek
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-06-28 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rake
|