human_user_agent 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/human_user_agent.gemspec +20 -0
- data/lib/human_user_agent.rb +24 -0
- data/lib/human_user_agent/version.rb +3 -0
- data/test/human_user_agent.rb +60 -0
- metadata +86 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Roger Campos
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# HumanUserAgent
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'human_user_agent'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install human_user_agent
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/human_user_agent/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Roger Campos"]
|
6
|
+
gem.email = ["roger@itnig.net"]
|
7
|
+
gem.description = %q{Get human readable user agent values from the raw value}
|
8
|
+
gem.summary = %q{Get human readable user agent values from the raw value}
|
9
|
+
gem.homepage = "https://github.com/rogercampos/human_user_agent"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "human_user_agent"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = HumanUserAgent::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'useragent', '>= 0.4.5'
|
19
|
+
gem.add_development_dependency 'minitest'
|
20
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'useragent'
|
2
|
+
|
3
|
+
module HumanUserAgent
|
4
|
+
extend self
|
5
|
+
|
6
|
+
def parse(raw_user_agent)
|
7
|
+
return nil if raw_user_agent.nil? || raw_user_agent == ""
|
8
|
+
raw_user_agent = raw_user_agent.to_s
|
9
|
+
|
10
|
+
if raw_user_agent =~ /MSIE (\d*\.\d*);/
|
11
|
+
"IE #{$1}"
|
12
|
+
else
|
13
|
+
uas = UserAgent.parse(raw_user_agent)
|
14
|
+
|
15
|
+
if uas[-2] && uas[-2].product =~ /Chrome/
|
16
|
+
"Chrome"
|
17
|
+
else
|
18
|
+
ua = uas[-1]
|
19
|
+
"#{ua.product} #{ua.version.to_s.split(".")[0..1].join(".")}"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require File.expand_path('../../lib/human_user_agent', __FILE__)
|
2
|
+
require 'minitest/autorun'
|
3
|
+
|
4
|
+
class TestHumanUserAgent < MiniTest::Unit::TestCase
|
5
|
+
def test_ie_7
|
6
|
+
raw_user_agent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; GTB7.3; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; .NET4.0C; BRI/2)"
|
7
|
+
assert_equal "IE 7.0", HumanUserAgent.parse(raw_user_agent)
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_ie_8
|
11
|
+
raw_user_agent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
|
12
|
+
assert_equal "IE 8.0", HumanUserAgent.parse(raw_user_agent)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_ie_9
|
16
|
+
raw_user_agent = "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)"
|
17
|
+
assert_equal "IE 9.0", HumanUserAgent.parse(raw_user_agent)
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_chrome
|
21
|
+
raw_user_agent = "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.46 Safari/536.5"
|
22
|
+
assert_equal "Chrome", HumanUserAgent.parse(raw_user_agent)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_firefox_11
|
26
|
+
raw_user_agent = "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:11.0) Gecko/20100101 Firefox/11.0"
|
27
|
+
assert_equal "Firefox 11.0", HumanUserAgent.parse(raw_user_agent)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_firefox_12
|
31
|
+
raw_user_agent = "Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20100101 Firefox/12.0"
|
32
|
+
assert_equal "Firefox 12.0", HumanUserAgent.parse(raw_user_agent)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_firefox_7
|
36
|
+
raw_user_agent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1"
|
37
|
+
assert_equal "Firefox 7.0", HumanUserAgent.parse(raw_user_agent)
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_firefox_3
|
41
|
+
raw_user_agent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; es-ES; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2"
|
42
|
+
assert_equal "Firefox 3.5", HumanUserAgent.parse(raw_user_agent)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_to_s_conversion
|
46
|
+
klass = Class.new do
|
47
|
+
def to_s
|
48
|
+
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Trident/4.0; GTB7.3; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; OfficeLiveConnector.1.5; OfficeLivePatch.1.3; .NET4.0C; BRI/2)"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
assert_equal "IE 7.0", HumanUserAgent.parse(klass.new)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_nil_or_blank_input
|
56
|
+
assert_equal nil, HumanUserAgent.parse(nil)
|
57
|
+
assert_equal nil, HumanUserAgent.parse("")
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: human_user_agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Roger Campos
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: useragent
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.4.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.4.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Get human readable user agent values from the raw value
|
47
|
+
email:
|
48
|
+
- roger@itnig.net
|
49
|
+
executables: []
|
50
|
+
extensions: []
|
51
|
+
extra_rdoc_files: []
|
52
|
+
files:
|
53
|
+
- .gitignore
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- human_user_agent.gemspec
|
59
|
+
- lib/human_user_agent.rb
|
60
|
+
- lib/human_user_agent/version.rb
|
61
|
+
- test/human_user_agent.rb
|
62
|
+
homepage: https://github.com/rogercampos/human_user_agent
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ! '>='
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 1.8.18
|
83
|
+
signing_key:
|
84
|
+
specification_version: 3
|
85
|
+
summary: Get human readable user agent values from the raw value
|
86
|
+
test_files: []
|