stella 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +135 -0
- data/Rakefile +100 -0
- data/bin/stella +12 -0
- data/lib/stella.rb +58 -0
- data/lib/stella/adapter/ab.rb +303 -0
- data/lib/stella/adapter/base.rb +87 -0
- data/lib/stella/adapter/httperf.rb +296 -0
- data/lib/stella/adapter/siege.rb +321 -0
- data/lib/stella/cli.rb +291 -0
- data/lib/stella/cli/agents.rb +73 -0
- data/lib/stella/cli/base.rb +19 -0
- data/lib/stella/cli/language.rb +18 -0
- data/lib/stella/cli/localtest.rb +80 -0
- data/lib/stella/command/base.rb +111 -0
- data/lib/stella/command/localtest.rb +339 -0
- data/lib/stella/logger.rb +63 -0
- data/lib/stella/response.rb +82 -0
- data/lib/stella/storable.rb +116 -0
- data/lib/stella/support.rb +106 -0
- data/lib/stella/test/base.rb +34 -0
- data/lib/stella/test/definition.rb +79 -0
- data/lib/stella/test/run/summary.rb +50 -0
- data/lib/stella/test/summary.rb +82 -0
- data/lib/stella/text.rb +64 -0
- data/lib/stella/text/resource.rb +39 -0
- data/lib/utils/crypto-key.rb +84 -0
- data/lib/utils/escape.rb +302 -0
- data/lib/utils/fileutil.rb +59 -0
- data/lib/utils/httputil.rb +210 -0
- data/lib/utils/mathutil.rb +78 -0
- data/lib/utils/textgraph.rb +267 -0
- data/lib/utils/timerutil.rb +58 -0
- data/support/text/en.yaml +54 -0
- data/support/text/nl.yaml +1 -0
- data/support/useragents.txt +75 -0
- data/vendor/useragent/MIT-LICENSE +20 -0
- data/vendor/useragent/README +21 -0
- data/vendor/useragent/init.rb +1 -0
- data/vendor/useragent/lib/user_agent.rb +83 -0
- data/vendor/useragent/lib/user_agent/browsers.rb +24 -0
- data/vendor/useragent/lib/user_agent/browsers/all.rb +69 -0
- data/vendor/useragent/lib/user_agent/browsers/gecko.rb +43 -0
- data/vendor/useragent/lib/user_agent/browsers/internet_explorer.rb +40 -0
- data/vendor/useragent/lib/user_agent/browsers/opera.rb +49 -0
- data/vendor/useragent/lib/user_agent/browsers/webkit.rb +94 -0
- data/vendor/useragent/lib/user_agent/comparable.rb +25 -0
- data/vendor/useragent/lib/user_agent/operating_systems.rb +19 -0
- data/vendor/useragent/spec/browsers/gecko_user_agent_spec.rb +209 -0
- data/vendor/useragent/spec/browsers/internet_explorer_user_agent_spec.rb +99 -0
- data/vendor/useragent/spec/browsers/opera_user_agent_spec.rb +59 -0
- data/vendor/useragent/spec/browsers/other_user_agent_spec.rb +19 -0
- data/vendor/useragent/spec/browsers/webkit_user_agent_spec.rb +373 -0
- data/vendor/useragent/spec/spec_helper.rb +1 -0
- data/vendor/useragent/spec/user_agent_spec.rb +331 -0
- data/vendor/useragent/useragent.gemspec +12 -0
- metadata +139 -0
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
require 'benchmark'
|
3
|
+
|
4
|
+
class TimerUtil
|
5
|
+
|
6
|
+
attr_reader :tstart, :tend, :rstart, :rend
|
7
|
+
attr_reader :time
|
8
|
+
|
9
|
+
def initialize(label="default")
|
10
|
+
@tstart, @rstart = 0,0
|
11
|
+
@tend, @rend = 0,0
|
12
|
+
@label = label
|
13
|
+
@time = Benchmark::Tms.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def start
|
17
|
+
@tstart, @rstart = Benchmark.times, Time.now
|
18
|
+
end
|
19
|
+
|
20
|
+
def stop
|
21
|
+
@tend, @rend = Benchmark.times, Time.now
|
22
|
+
|
23
|
+
@time = Benchmark::Tms.new(@tend.utime - @tstart.utime,
|
24
|
+
@tend.stime - @tstart.stime,
|
25
|
+
@tend.cutime - @tstart.cutime,
|
26
|
+
@tend.cstime - @tstart.cstime,
|
27
|
+
@rend.to_f - @rstart.to_f,
|
28
|
+
@label)
|
29
|
+
end
|
30
|
+
|
31
|
+
def utime
|
32
|
+
@time.utime
|
33
|
+
end
|
34
|
+
def stime
|
35
|
+
@time.stime
|
36
|
+
end
|
37
|
+
def cutime
|
38
|
+
@time.cutime
|
39
|
+
end
|
40
|
+
def cstime
|
41
|
+
@time.cstime
|
42
|
+
end
|
43
|
+
def total
|
44
|
+
@time.total
|
45
|
+
end
|
46
|
+
def real
|
47
|
+
@time.real
|
48
|
+
end
|
49
|
+
def format(formatstr=nil)
|
50
|
+
@time.format(formatstr)
|
51
|
+
end
|
52
|
+
def label
|
53
|
+
@time.label
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
:info:
|
2
|
+
:language: en
|
3
|
+
:fullname: english
|
4
|
+
:updated: 2008-12-20
|
5
|
+
:enabled: true
|
6
|
+
:text_available_languages: "Available languages: %s"
|
7
|
+
|
8
|
+
|
9
|
+
:agents_option_full: Return complete user-agent strings.
|
10
|
+
:agents_option_list: List available user-agent shortnames.
|
11
|
+
:agents_option_search: Return only user agents which match the search term.
|
12
|
+
:agents_count_message: "There are %d user agent strings matching your query"
|
13
|
+
|
14
|
+
:option_help_stdout: Print STDOUT output from load tool for each test run
|
15
|
+
:option_help_stderr: Print STDERR output from load tool for each test run
|
16
|
+
:option_help_verbose: Specify the output verbosity (level 1, 2 or 3)
|
17
|
+
:option_help_testreps: Number of test repetitions to execute (testruns).
|
18
|
+
:cli_print_version: "Stella version: %s"
|
19
|
+
:option_help_quiet: Demand only the essential output for each run.
|
20
|
+
:option_help_warmup: "Include a warmup run, a factor N of the test load. Default: %f"
|
21
|
+
:option_help_usage: "Usage: stella [OPTIONS] COMMAND [COMMAND OPTIONS]"
|
22
|
+
:option_help_options_title: "Options:"
|
23
|
+
:option_help_overhead: Show the time used by Stella before and after the run.
|
24
|
+
:option_help_datapath: "Directory path to store test data. Default: %s"
|
25
|
+
:option_help_preamble: |
|
26
|
+
|
27
|
+
Commands:
|
28
|
+
%s
|
29
|
+
|
30
|
+
Examples:
|
31
|
+
|
32
|
+
# Run Apache Bench with 50 users, 20 requests each. Repeat 5 times.
|
33
|
+
$ stella -t 5 ab -n 1000 -c 50 http://stellaaahhhh.com/
|
34
|
+
|
35
|
+
# Run Siege with 100 users, 10 requests each with a Linux FireFox 3 user agent
|
36
|
+
$ stella -a firefox-3-linux siege -c 100 -r 10 http://stellaaahhhh.com/
|
37
|
+
|
38
|
+
User-Agent Examples (--agent):
|
39
|
+
ff-3-linux, ie-7-win, opera-10, chrome-0.2-osx
|
40
|
+
|
41
|
+
:option_help_message: A short note about the test (i.e. 'new cache enabled')
|
42
|
+
:option_help_format: "Output file format. One of: csv [default], yaml, tsv, json"
|
43
|
+
:option_help_version: Display the version, then exit
|
44
|
+
:option_help_sleep: Number of seconds to sleep between runs
|
45
|
+
:option_help_agent: Specify a User-Agent. Can be a short string or complete agent string. Defaults to 'random'.
|
46
|
+
:option_help_help: Displays this message
|
47
|
+
:option_help_rampup: Execute multiple tests, incremented by R users every test, up to U users
|
48
|
+
|
49
|
+
:error_unavailable_adapter: "The adapter %s is not available. Check your PATH."
|
50
|
+
:error_class_must_override: "You must override the method: %s"
|
51
|
+
:error_class_unknown_argument: "Ignoring unknown argument: %s"
|
52
|
+
:error_adapter_command_not_ready: "Incomplete options or arguments for %s"
|
53
|
+
:error_invalid_argument: "%s is not a valid argument"
|
54
|
+
:error_unknown_value: "I don't know what to do with %s"
|
@@ -0,0 +1 @@
|
|
1
|
+
---
|
@@ -0,0 +1,75 @@
|
|
1
|
+
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3
|
2
|
+
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.3) Gecko/2008092414 Firefox/3.0.3
|
3
|
+
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_5; en-us) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1
|
4
|
+
Opera/9.50 (X11; Linux i686; U; en)
|
5
|
+
Mozilla/5.0 (X11; U; FreeBSD amd64; en; rv:1.8.1.16) Gecko/20080827 Epiphany/2.22 Firefox/2.0.0.16
|
6
|
+
Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.8.1.16) Gecko/20080827 Firefox/2.0.0.16
|
7
|
+
Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.0.2) Gecko/2008100107 Firefox/3.0.2
|
8
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008111318 Ubuntu/8.10 (intrepid) Firefox/3.0.4
|
9
|
+
Opera/9.52 (X11; FreeBSD 7.0-RELEASE amd64; U; en)
|
10
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.13) Gecko/20080311 (Debian-1.8.1.13+nobinonly-0ubuntu1) Galeon/2.0.4 (Ubuntu 2.0.4-1ubuntu1)
|
11
|
+
Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.8.1.16) Gecko/20080827 Galeon/2.0.6 Firefox/2.0.0.16
|
12
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3
|
13
|
+
Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.8.1.16) Gecko/20080827 SeaMonkey/1.1.11
|
14
|
+
Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.18) Gecko/20081112 Fedora/1.1.13-1.fc10 SeaMonkey/1.1.13
|
15
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/0.4.154.29 Safari/525.19
|
16
|
+
Opera/9.51 (X11; Linux i686; U; en)
|
17
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8) Gecko/20051111 Firefox/1.5
|
18
|
+
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)
|
19
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1a2) Gecko/20080829082037 Shiretoko/3.1a2
|
20
|
+
Dillo/0.8.6-i18n-misc
|
21
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9) Gecko/2008061302 Firefox/3.0 Flock/2.0b1
|
22
|
+
Opera/9.27 (X11; Linux i686; U; en)
|
23
|
+
Opera/10.00 (Windows NT 5.1; U; en) Presto/2.2.0
|
24
|
+
Opera/9.27 (Windows NT 5.0; U; de)
|
25
|
+
Opera/9.62 (X11; Linux i686; U; de) Presto/2.1.1
|
26
|
+
Opera/9.62 (Windows NT 5.1; U; en) Presto/2.1.1
|
27
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1pre) Gecko/20080911002759 SeaMonkey/2.0a1pre
|
28
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080910 Firefox/2.0.0.17 Flock/1.2.6
|
29
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.0; de-DE; rv:1.8.1.12) Gecko/20080203 K-Meleon/1.1.4
|
30
|
+
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
|
31
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.18) Gecko/20081031 SeaMonkey/1.1.13
|
32
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.0; de; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4
|
33
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.27.1 (KHTML, like Gecko) Version/3.2.1 Safari/525.27.1
|
34
|
+
Opera/8.53 (Windows NT 5.1; U; en)
|
35
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.4) Gecko/2008112016 Firefox/3.0.4 Flock/2.0.2
|
36
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.18) Gecko/20081030 Iceape/1.1.13 (Debian-1.1.13-1)
|
37
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko/2008112309 Iceweasel/3.0.4 (Debian-3.0.4-1)
|
38
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; de-DE; rv:1.8.1.17pre) Gecko/20080716 K-Meleon/1.5.0
|
39
|
+
Opera/9.26 (Windows NT 5.0; U; de)
|
40
|
+
Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.10 (like Gecko) (Debian)
|
41
|
+
Mozilla/5.0 (X11; U; Linux i686; en; rv:1.9.0.4) Gecko/20080528 Epiphany/2.22
|
42
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1
|
43
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.14eol) Gecko/20070505 (Debian-1.8.0.15~pre080614d-0etch1) Epiphany/2.14
|
44
|
+
Opera/9.52 (X11; Linux i686; U; en)
|
45
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.1.11pre) Gecko/20071206 Firefox/2.0.0.11 Navigator/9.0.0.5
|
46
|
+
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)
|
47
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2a1pre) Gecko/20081206 Minefield/3.2a1pre
|
48
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.4) Gecko Kazehakase/0.5.4 Debian/0.5.4-2.1ubuntu3
|
49
|
+
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser)
|
50
|
+
Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.36 Safari/525.19
|
51
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.14eol) Gecko/20070505 Iceape/1.0.9 (Debian-1.0.13~pre080323b-0etch3)
|
52
|
+
Opera/9.25 (Windows NT 5.1; U; de)
|
53
|
+
Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) Opera 7.11 [en]
|
54
|
+
Mozilla/4.0 (compatible; MSIE 4.01; Windows NT 5.0; SV1)
|
55
|
+
Opera/9.51 (Windows NT 5.1; U; en)
|
56
|
+
Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)
|
57
|
+
Opera/9.61 (Windows NT 5.1; U; en) Presto/2.1.1
|
58
|
+
Opera/9.50 (Windows NT 5.1; U; en)
|
59
|
+
Opera/9.52 (Windows NT 5.1; U; en)
|
60
|
+
Opera/9.24 (Windows NT 5.1; U; it)
|
61
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/523.12.9 (KHTML, like Gecko) Version/3.0 Safari/523.12.9
|
62
|
+
Opera/9.23 (Windows NT 5.1; U; it)
|
63
|
+
Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1)
|
64
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.18) Gecko/20081030 Iceweasel/2.0.0.18 (Debian-2.0.0.18-0etch1)
|
65
|
+
Mozilla/5.0 (X11; Linux i686; U;) Gecko/0 Kazehakase/0.4.2 Debian/0.4.2-1etch1
|
66
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9b5pre) Gecko/2008031501 SeaMonkey/2.0a1pre
|
67
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Flock/1.1d
|
68
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080219 Firefox/2.0.0.12 Navigator/9.0.0.6
|
69
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a1) Gecko/2008072306 Shiretoko/3.1a1
|
70
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.12) Gecko/20080211 Firefox/2.0.0.12 Flock/1.0.9
|
71
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.2.149.30 Safari/525.13
|
72
|
+
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1b3pre) Gecko/20081201 Minefield/3.1b3pre
|
73
|
+
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.18) Gecko/20081030 Iceweasel/2.0.0.18 (Debian-2.0.0.18-0etch1)
|
74
|
+
Opera/10.00 (X11; Linux i686 ; U; en) Presto/2.2.0
|
75
|
+
Mozilla/5.0 (Windows; U; Windows NT 6.0; nl-NL) AppleWebKit/525.19 (KHTML, like Gecko) Version/3.1.2 Safari/525.21
|
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Joshua Peek
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,21 @@
|
|
1
|
+
UserAgent
|
2
|
+
=========
|
3
|
+
|
4
|
+
UserAgent is a Ruby library that parses and compares HTTP User Agents.
|
5
|
+
|
6
|
+
|
7
|
+
Example
|
8
|
+
=======
|
9
|
+
|
10
|
+
Browser = Struct.new(:browser, :version)
|
11
|
+
SupportedBrowsers = [
|
12
|
+
Browser.new("Safari", "3.1.1"),
|
13
|
+
Browser.new("Firefox", "2.0.0.14"),
|
14
|
+
Browser.new("Internet Explorer", "7.0")
|
15
|
+
]
|
16
|
+
|
17
|
+
user_agent = UserAgent.parse(request.user_agent)
|
18
|
+
SupportedBrowsers.detect { |browser| user_agent >= browser }
|
19
|
+
|
20
|
+
|
21
|
+
Copyright (c) 2008 Joshua Peek, released under the MIT license
|
@@ -0,0 +1 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/lib/user_agent'
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/user_agent/comparable"
|
2
|
+
require "#{File.dirname(__FILE__)}/user_agent/browsers"
|
3
|
+
require "#{File.dirname(__FILE__)}/user_agent/operating_systems"
|
4
|
+
|
5
|
+
class UserAgent
|
6
|
+
# http://www.texsoft.it/index.php?m=sw.php.useragent
|
7
|
+
MATCHER = %r{
|
8
|
+
^([^/\s]+) # Product
|
9
|
+
/?([^\s]*) # Version
|
10
|
+
(\s\(([^\)]*)\))? # Comment
|
11
|
+
}x.freeze unless defined? MATCHER
|
12
|
+
|
13
|
+
def self.parse(string)
|
14
|
+
agents = []
|
15
|
+
while m = string.match(MATCHER)
|
16
|
+
agent = new(m[1], m[2], m[4], string)
|
17
|
+
agents << agent
|
18
|
+
string = string.sub(agent.to_s, '').strip
|
19
|
+
end
|
20
|
+
Browsers.extend(agents)
|
21
|
+
agents
|
22
|
+
end
|
23
|
+
|
24
|
+
attr_accessor :product, :version, :comment, :original
|
25
|
+
|
26
|
+
def initialize(product, version = nil, comment = nil, original = nil)
|
27
|
+
if product
|
28
|
+
@product = product
|
29
|
+
else
|
30
|
+
raise ArgumentError, "expected a value for product"
|
31
|
+
end
|
32
|
+
|
33
|
+
if version && version.any?
|
34
|
+
@version = version
|
35
|
+
end
|
36
|
+
|
37
|
+
if comment.respond_to?(:split)
|
38
|
+
@comment = comment.split("; ")
|
39
|
+
else
|
40
|
+
@comment = comment
|
41
|
+
end
|
42
|
+
|
43
|
+
@original = original
|
44
|
+
end
|
45
|
+
|
46
|
+
include Comparable
|
47
|
+
|
48
|
+
# Any comparsion between two user agents with different products will
|
49
|
+
# always return false.
|
50
|
+
def <=>(other)
|
51
|
+
if @product == other.product
|
52
|
+
if @version && other.version
|
53
|
+
@version <=> other.version
|
54
|
+
else
|
55
|
+
0
|
56
|
+
end
|
57
|
+
else
|
58
|
+
false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def eql?(other)
|
63
|
+
@product == other.product &&
|
64
|
+
@version == other.version &&
|
65
|
+
@comment == other.comment
|
66
|
+
end
|
67
|
+
|
68
|
+
def to_s
|
69
|
+
to_str
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_str
|
73
|
+
if @product && @version && @comment
|
74
|
+
"#{@product}/#{@version} (#{@comment.join("; ")})"
|
75
|
+
elsif @product && @version
|
76
|
+
"#{@product}/#{@version}"
|
77
|
+
elsif @product && @comment
|
78
|
+
"#{@product} (#{@comment.join("; ")})"
|
79
|
+
else
|
80
|
+
@product
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Dir["#{File.dirname(__FILE__)}/browsers/*.rb"].each do |browser|
|
2
|
+
require browser
|
3
|
+
end
|
4
|
+
|
5
|
+
class UserAgent
|
6
|
+
module Browsers
|
7
|
+
Security = {
|
8
|
+
"N" => :none,
|
9
|
+
"U" => :strong,
|
10
|
+
"I" => :weak
|
11
|
+
}.freeze unless defined? Security
|
12
|
+
|
13
|
+
def self.all
|
14
|
+
[InternetExplorer, Webkit, Opera, Gecko]
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.extend(array)
|
18
|
+
array.extend(All)
|
19
|
+
all.each do |extension|
|
20
|
+
return array.extend(extension) if extension.extend?(array)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
class UserAgent
|
2
|
+
module Browsers
|
3
|
+
module All
|
4
|
+
include Comparable
|
5
|
+
|
6
|
+
def <=>(other)
|
7
|
+
if respond_to?(:browser) && other.respond_to?(:browser) &&
|
8
|
+
browser == other.browser
|
9
|
+
version <=> other.version
|
10
|
+
else
|
11
|
+
false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def eql?(other)
|
16
|
+
self == other
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
to_str
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_str
|
24
|
+
join(" ")
|
25
|
+
end
|
26
|
+
|
27
|
+
def application
|
28
|
+
first
|
29
|
+
end
|
30
|
+
|
31
|
+
def browser
|
32
|
+
application.product
|
33
|
+
end
|
34
|
+
|
35
|
+
def platform
|
36
|
+
"Unknown"
|
37
|
+
end
|
38
|
+
|
39
|
+
def os
|
40
|
+
"Unknown"
|
41
|
+
end
|
42
|
+
|
43
|
+
def version=(v)
|
44
|
+
application.version = v
|
45
|
+
end
|
46
|
+
|
47
|
+
def original
|
48
|
+
application.original
|
49
|
+
end
|
50
|
+
|
51
|
+
def version
|
52
|
+
application.version
|
53
|
+
end
|
54
|
+
|
55
|
+
def respond_to?(symbol)
|
56
|
+
detect_product(symbol) ? true : super
|
57
|
+
end
|
58
|
+
|
59
|
+
def method_missing(method, *args, &block)
|
60
|
+
detect_product(method) || super
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
def detect_product(product)
|
65
|
+
detect { |useragent| useragent.product.to_s.downcase == product.to_s.downcase }
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class UserAgent
|
2
|
+
module Browsers
|
3
|
+
module Gecko
|
4
|
+
def self.extend?(agent)
|
5
|
+
agent.application && agent.application.product == "Mozilla"
|
6
|
+
end
|
7
|
+
|
8
|
+
GeckoBrowsers = %w(
|
9
|
+
Firefox
|
10
|
+
Camino
|
11
|
+
).freeze unless defined? GeckoBrowsers
|
12
|
+
|
13
|
+
def browser
|
14
|
+
GeckoBrowsers.detect { |browser| respond_to?(browser) } || super
|
15
|
+
end
|
16
|
+
|
17
|
+
def version
|
18
|
+
send(browser).version || super
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def version=(v)
|
23
|
+
send(browser).version = v
|
24
|
+
end
|
25
|
+
|
26
|
+
def platform
|
27
|
+
application.comment[0]
|
28
|
+
end
|
29
|
+
|
30
|
+
def security
|
31
|
+
Security[application.comment[1]]
|
32
|
+
end
|
33
|
+
|
34
|
+
def os
|
35
|
+
OperatingSystems.normalize_os(application.comment[2])
|
36
|
+
end
|
37
|
+
|
38
|
+
def localization
|
39
|
+
application.comment[3]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|