Class: AgentSpec
- Inherits:
-
Object
- Object
- AgentSpec
- Defined in:
- lib/active_device/agent_spec.rb
Instance Attribute Summary collapse
-
#user_agent ⇒ Object
readonly
User agent user_agent.
Class Method Summary collapse
-
.engine_for_user_agent(user_agent) ⇒ Object
Return engine symbol for user agent user_agent.
-
.engine_version_for_user_agent(user_agent) ⇒ Object
Return engine version for user agent user_agent.
-
.map(name, options = {}) ⇒ Object
Map agent name to options.
-
.name_for_user_agent(user_agent) ⇒ Object
Return name for user agent user_agent.
-
.os_for_user_agent(user_agent) ⇒ Object
Return the os for user agent user_agent.
- .os_series_for_user_agent(user_agent) ⇒ Object
-
.os_version_for_user_agent(user_agent) ⇒ Object
Return version for user agent user_agent.
-
.version_for_user_agent(user_agent) ⇒ Object
Return version for user agent user_agent.
Instance Method Summary collapse
-
#initialize(user_agent) ⇒ AgentSpec
constructor
Initialize with user agent user_agent.
Constructor Details
#initialize(user_agent) ⇒ AgentSpec
Initialize with user agent user_agent.
11 12 13 |
# File 'lib/active_device/agent_spec.rb', line 11 def initialize user_agent @user_agent = user_agent.strip end |
Instance Attribute Details
#user_agent ⇒ Object (readonly)
User agent user_agent.
6 7 8 |
# File 'lib/active_device/agent_spec.rb', line 6 def user_agent @user_agent end |
Class Method Details
.engine_for_user_agent(user_agent) ⇒ Object
Return engine symbol for user agent user_agent.
112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/active_device/agent_spec.rb', line 112 def self.engine_for_user_agent user_agent case user_agent when /webkit/i ; :Webkit when /khtml/i ; :khtml when /konqueror/i ; :Konqueror when /chrome/i ; :Chrome when /presto/i ; :Presto when /gecko/i ; :Gecko when /msie/i ; :MSIE when /NetFront/i ; :NetFront when /UP.Browser/i; :'UP.Browser' else :Unknown end end |
.engine_version_for_user_agent(user_agent) ⇒ Object
Return engine version for user agent user_agent.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/active_device/agent_spec.rb', line 18 def self.engine_version_for_user_agent user_agent engine = engine_for_user_agent(user_agent) case engine when :Webkit; if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i $1 elsif user_agent =~ /#{engine}([0-9\.\-]+)/i $1 end when :NetFront; if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i $1 elsif user_agent =~ /#{engine}([0-9\.\-]+)/i $1 end when :'UP.Browser'; if user_agent =~ /#{engine}[\/ ]([\d\w\.\-]+)/i $1 elsif user_agent =~ /#{engine}([0-9\.\-]+)/i $1 end else $1 if user_agent =~ /#{engine_for_user_agent(user_agent)}[\/ ]([\d\w\.\-]+)/i end end |
.map(name, options = {}) ⇒ Object
Map agent name to options.
178 179 180 |
# File 'lib/active_device/agent_spec.rb', line 178 def self.map name, = {} @agents << [name, ] end |
.name_for_user_agent(user_agent) ⇒ Object
Return name for user agent user_agent.
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/active_device/agent_spec.rb', line 157 def self.name_for_user_agent user_agent case user_agent when /konqueror/i ; :Konqueror when /chrome/i ; :Chrome when /safari/i ; :Safari when /msie/i ; :IE when /opera/i ; :Opera when /playstation 3/i ; :PS3 when /playstation portable/i ; :PSP when /SymbianOS/i ; :SymbianOS when /Symbian/i ; :Symbian when /iPhone/i ; :iPhone else ; :Unknown end end |
.os_for_user_agent(user_agent) ⇒ Object
Return the os for user agent user_agent.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/active_device/agent_spec.rb', line 130 def self.os_for_user_agent user_agent case user_agent when /windows ce/i ; :'Windows CE' when /windows nt 6\.0/i ; :'Windows Vista' when /windows nt 6\.\d+/i ; :'Windows 7' when /windows nt 5\.2/i ; :'Windows 2003' when /windows nt 5\.1/i ; :'Windows XP' when /windows nt 5\.0/i ; :'Windows 2000' when /windows nt 4\.0/i ; :Windows when /os x (\d+)[._](\d+)/i ; :"OS X #{$1}.#{$2}" when /linux/i ; :Linux when /wii/i ; :Wii when /playstation 3/i ; :Playstation when /playstation portable/i ; :Playstation when /SymbianOS/i ; :SymbianOS when /Symbian/i ; :Symbian when /Palm/i ; :Palm when /iPhone/i ; :iPhone else ; :Unknown end end |
.os_series_for_user_agent(user_agent) ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/active_device/agent_spec.rb', line 101 def self.os_series_for_user_agent user_agent case os_for_user_agent(user_agent) when :SymbianOS ; :"#{user_agent[/series[\w\-\.\/]*/i]}" if user_agent =~ /series[\w\-\.\/]*/i when :Symbian ; $1 if user_agent =~ /\ ([0-9\d\w\.\-]+)\)?\s*$/i else $1 if user_agent =~ /[\/ ]([\d\w\.\-]+)/i end end |
.os_version_for_user_agent(user_agent) ⇒ Object
Return version for user agent user_agent.
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 |
# File 'lib/active_device/agent_spec.rb', line 74 def self.os_version_for_user_agent user_agent os = os_for_user_agent(user_agent) case os when :Chrome ; $1 if user_agent =~ /chrome\/([\d\w\.\-]+)/i when :Safari; if user_agent =~ /version\/([\d\w\.\-]+)/i $1 elsif user_agent =~ /Safari([\d0-9\.\-]+)/i $1 elsif user_agent =~ /Safari\/([\d0-9\.\-]+)/i $1 end when :PS3 ; $1 if user_agent =~ /([\d\w\.\-]+)\)\s*$/i when :PSP ; $1 if user_agent =~ /([\d\w\.\-]+)\)?\s*$/i when :SymbianOS; if user_agent =~ /symbianos\/([\d\w\.\-]+)/i $1 elsif user_agent =~ /SymbianOS([\d0-9\.\-]+)/i $1 end when :Symbian ; $1 if user_agent =~ /\ ([0-9\d\w\.\-]+)\)?\s*$/i when :iPhone ; $1 if user_agent =~ /OS\ ([0-9\.\-\_]+)/i when :IE ; $1 if user_agent =~ /IEMobile[\/ ]([\d\w\.\-]+)/i else $1 if user_agent =~ /#{os}[\/ ]([\d\w\.\-]+)/i end end |
.version_for_user_agent(user_agent) ⇒ Object
Return version for user agent user_agent.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/active_device/agent_spec.rb', line 46 def self.version_for_user_agent user_agent name = name_for_user_agent(user_agent) case name when :Chrome ; $1 if user_agent =~ /chrome\/([\d\w\.\-]+)/i when :Safari ; if user_agent =~ /version\/([\d\w\.\-]+)/i $1 elsif user_agent =~ /Safari([0-9\.\-]+)/i $1 else user_agent =~ /Safari\/([0-9\.\-]+)/i $1 end when :PS3 ; $1 if user_agent =~ /([\d\w\.\-]+)\)\s*$/i when :PSP ; $1 if user_agent =~ /([\d\w\.\-]+)\)?\s*$/i # when :SymbianOS ; $1 if user_agent =~ /\/([\d\w\.\-]+)/i #\)?\s*$ # when :Symbian ; $1 if user_agent =~ /\ ([0-9\d\w\.\-]+)\)?\s*$/i # when :iPhone ; $1 if user_agent =~ /([\d\w\.\-]+)\)?\s*$/i #when name[/safari([0-9\-\.\_]+)/i] ; $1 if name =~ /([0-9\-\.\_]+)/i else $1 if user_agent =~ /#{name.to_s}[\/ ]([\d\w\.\-]+)/i end end |