loyal_user_agent 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ = UserAgent
2
+
3
+ UserAgent is a Ruby library that parses and compares HTTP User Agents.
4
+
5
+ === Installation
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
+
22
+ ==== Comparison
23
+
24
+ Browser = Struct.new(:browser, :version)
25
+ SupportedBrowsers = [
26
+ Browser.new("Safari", "3.1.1"),
27
+ Browser.new("Firefox", "2.0.0.14"),
28
+ Browser.new("Internet Explorer", "7.0")
29
+ ]
30
+
31
+ user_agent = UserAgent.parse(request.user_agent)
32
+ SupportedBrowsers.detect { |browser| user_agent >= browser }
33
+
34
+
35
+ Copyright (c) 2013 Joshua Peek, released under the MIT license
@@ -0,0 +1,7 @@
1
+ require 'rspec/core/rake_task'
2
+
3
+ task :default => :spec
4
+
5
+ RSpec::Core::RakeTask.new do |t|
6
+ t.ruby_opts = ["-w"]
7
+ end
@@ -0,0 +1 @@
1
+ require 'user_agent'
@@ -0,0 +1,31 @@
1
+ require 'user_agent/action_controller_able'
2
+
3
+ class UserAgent
4
+ attr_reader :user_agent_string
5
+
6
+ MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
7
+ 'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
8
+ 'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
9
+ 'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
10
+ 'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
11
+ 'mobile'
12
+
13
+ MOBILE_USER_AGENTS_REGEXP = ::Regexp.new(MOBILE_USER_AGENTS)
14
+
15
+ def initialize(ua='')
16
+ @user_agent_string = ua.to_s.downcase
17
+ end
18
+
19
+ def mobile_device?
20
+ !!(@user_agent_string =~ MOBILE_USER_AGENTS_REGEXP)
21
+ end
22
+
23
+ def device?(type)
24
+ @user_agent_string.include?(type.to_s.downcase)
25
+ end
26
+ end
27
+
28
+ if defined? ActionController::Base
29
+ ::ActionController::Base.send :include, ::UserAgent::ActionControllerAble
30
+ end
31
+
@@ -0,0 +1,17 @@
1
+ class UserAgent
2
+ module ActionControllerAble
3
+ def self.included base
4
+ base.class_eval do
5
+ include InstanceMethods
6
+
7
+ helper_method :current_user_agent
8
+ end
9
+ end
10
+
11
+ module InstanceMethods
12
+ def current_user_agent
13
+ @current_user_agent ||= ::UserAgent.new(request.user_agent)
14
+ end
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: loyal_user_agent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Joshua Peek
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-08-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
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: |2
47
+ HTTP User Agent parser
48
+ email: josh@joshpeek.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/user_agent.rb
54
+ - lib/user_agent/action_controller_able.rb
55
+ - lib/loyal_user_agent.rb
56
+ - Rakefile
57
+ - README.rdoc
58
+ homepage: http://github.com/josh/useragent
59
+ licenses: []
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ requirements: []
77
+ rubyforge_project:
78
+ rubygems_version: 1.8.25
79
+ signing_key:
80
+ specification_version: 3
81
+ summary: HTTP User Agent parser
82
+ test_files: []