Class: SoldierOfCode::SpyVsSpy
- Inherits:
-
Object
- Object
- SoldierOfCode::SpyVsSpy
- Defined in:
- lib/spy_vs_spy.rb
Defined Under Namespace
Classes: Middleware, OS, Version
Constant Summary collapse
- SafariSpecialCases =
{ "1.0" => ["85.5", "85.6", "85.7"], "1,0.3" => ["85.8.1", "85.8", "85"], "1.2" => ["125", "125.1"], "1.2.2" => ["85.8", "125.7", "125.8"], "1.2.3" => ["100", "125.9"], "1.2.4" => ["125", "125.11", "125.12", "125.12_Adobe", "125.5.5"], "1.3" => ["312", "312.3.1"], "1.3.1" => ["312.3.3", "312.3.1", "312.3", "125.8", "125.9"], "1.3.2" => ["312.3.3", "312.5", "312.6", "312.5_Adobe"], "2.0" => ["412", "412.2.2", "412.2_Adobe"], "2.0.1" => ["412.5", "412.6", "412.5_Adobe"], "2.0.2" => ["416.13", "416.12", "312", "416.13_Adobe", "416.12_Adobe", "412.5"], "2.0.3" => ["417.9.3", "417.8_Adobe", "417.9.2", "417.8", "412.2"], "2.0.4" => ["419.3"], "3.0" => ["523.13", "522.11.3", "523.12.9", "523.6.1", "522.11.1", "522.11", "522.8.3", "522.7"], "3.0.1" => ["522.12.2"], "3.0.2" => ["522.13.1", "522.12"], "3.0.3" => ["522.15.5", "523.6", "522.12.1"], "3.0.4" => ["523.11", "523.12.2", "523.10", "523.10.6", "523.15", "523.12"], "3.1.1" => ["525.17", "525.18", "525.20"], "3.2.1" => ["525.27.1"] }
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#browser ⇒ Object
readonly
Returns the value of attribute browser.
-
#console_browser ⇒ Object
readonly
Returns the value of attribute console_browser.
-
#mobile_browser ⇒ Object
readonly
Returns the value of attribute mobile_browser.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
-
#os_version ⇒ Object
readonly
Returns the value of attribute os_version.
-
#platform ⇒ Object
readonly
Returns the value of attribute platform.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #complete? ⇒ Boolean
-
#identify_platform(agent) ⇒ Object
description: —————-.
-
#initialize(agent) ⇒ SpyVsSpy
constructor
description: —————-.
-
#is_mobile?(agent) ⇒ Boolean
description: —————-.
-
#process_firefox(agent) ⇒ Object
description: —————-.
-
#process_ie(agent) ⇒ Object
description: —————-.
-
#process_netscape(agent) ⇒ Object
description: —————-.
-
#process_opera(agent) ⇒ Object
description: —————-.
-
#process_safari(agent_string) ⇒ Object
description: —————-.
Constructor Details
#initialize(agent) ⇒ SpyVsSpy
description:
params:
returns:
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/spy_vs_spy.rb', line 130 def initialize(agent) @agent = agent pass1 = Regexp.new("^([^\\(]*)?[ ]*?(\\([^\\)]*\\))?[ ]*([^\\(]*)?[ ]*?(\\([^\\)]*\\))?[ ]*(.*)") if matches = pass1.match(agent) @product_token = matches[1] || '' @detail = matches[2] || '' @engine = matches[3] || '' @renderer = matches[4] || '' @identifier = matches[5] || '' @platform = identify_platform(agent) @mobile = is_mobile?(agent) @os = OS.new(@detail) @version = Version.new [:safari, :firefox, :ie, :opera, :netscape].each do |type| send(:"process_#{type}", agent) break if complete? end end end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def agent @agent end |
#browser ⇒ Object (readonly)
Returns the value of attribute browser.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def browser @browser end |
#console_browser ⇒ Object (readonly)
Returns the value of attribute console_browser.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def console_browser @console_browser end |
#mobile_browser ⇒ Object (readonly)
Returns the value of attribute mobile_browser.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def mobile_browser @mobile_browser end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def os @os end |
#os_version ⇒ Object (readonly)
Returns the value of attribute os_version.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def os_version @os_version end |
#platform ⇒ Object (readonly)
Returns the value of attribute platform.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def platform @platform end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
117 118 119 |
# File 'lib/spy_vs_spy.rb', line 117 def version @version end |
Instance Method Details
#complete? ⇒ Boolean
186 187 188 |
# File 'lib/spy_vs_spy.rb', line 186 def complete? @browser && @version.major end |
#identify_platform(agent) ⇒ Object
description:
params:
returns:
166 167 168 169 |
# File 'lib/spy_vs_spy.rb', line 166 def identify_platform(agent) (match = /(PLAYSTATION 3|wii|PlayStation Portable|Xbox|iPhone|iPod|BlackBerry|Android|HTC-|LG|Motorola|Nokia|Treo|Pre\/|Samsung|SonyEricsson)/.match(agent)) ? match[1] : 'Desktop' end |
#is_mobile?(agent) ⇒ Boolean
description:
params:
returns:
182 183 184 |
# File 'lib/spy_vs_spy.rb', line 182 def is_mobile?(agent) /(iPhone|iPod|BlackBerry|Android|HTC-|LG|Motorola|Nokia|Treo|Pre\/|Samsung|SonyEricsson)/.match(agent) end |
#process_firefox(agent) ⇒ Object
description:
params:
returns:
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/spy_vs_spy.rb', line 369 def process_firefox(agent) @identifier = @engine if @identifier == "" if agent.include?("Firefox") @browser = "Firefox" end if @identifier.include?("Firefox") || @renderer.include?("Firefox") || @engine.include?("Firefox") @browser = "Firefox" identifier_sub = nil @identifier.gsub(/[\\:\?'"%!@#\$\^&\*\(\)\+]/, '').split(" ").find do |ident| if ident.include?("Firefox") identifier_sub = ident.sub("Firefox\/", "").sub("Gecko/", "") identifier_sub.gsub!(/[\+]/, '') end identifier_sub end if identifier_sub.nil? && @renderer.include?("Firefox") renderer_gsub_gsub = @renderer.sub("\(", "").sub("\)", "") renderer_gsub_gsub.strip.split(",").each do |sec| identifier_sub = sec.sub("Firefox\/", "").strip if sec.include?("Firefox") end end if identifier_sub.nil? && @engine.include?("Firefox") @engine.gsub(/[\\:\?'"%!@#\$\^&\*\(\)\+]/, '').split(" ").each do |ident| identifier_sub = ident.sub("Firefox\/", "").sub("Gecko/", "") if ident.include?("Firefox") identifier_sub.gsub!(/[\+]/, '') if identifier_sub && identifier_sub.include?("+") end end identifier_sub.gsub!(/;.*/, '') if identifier_sub @version.update(*identifier_sub.split(".")) end end end |
#process_ie(agent) ⇒ Object
description:
params:
returns:
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
# File 'lib/spy_vs_spy.rb', line 334 def process_ie(agent) # @detail if agent.include?("MSIE") @browser = "MSIE" end if @detail.include?("MSIE") @detail.gsub(/[\\:\?'"%!@#\$\^&\*\(\)\+]/, '').split(";").each do |sec| if sec.strip.index("MSIE ") == 0 @version.update(*sec.strip.sub("MSIE ", "").gsub(/0(\d)/, '0.\1').split(/[.,]/)) end break if @version.major end end unless @version.major if match = /MSIE ([6789])\.0/.match(agent) @browser = "MSIE" @version.major = match[1] @version.minor = '0' end end end |
#process_netscape(agent) ⇒ Object
description:
params:
returns:
434 435 436 |
# File 'lib/spy_vs_spy.rb', line 434 def process_netscape(agent) end |
#process_opera(agent) ⇒ Object
description:
params:
returns:
419 420 421 |
# File 'lib/spy_vs_spy.rb', line 419 def process_opera(agent) end |
#process_safari(agent_string) ⇒ Object
description:
params:
returns:
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# File 'lib/spy_vs_spy.rb', line 201 def process_safari(agent_string) @identifier = @engine if @identifier == "" if agent_string.include?("Safari") @browser = "Safari" end if @identifier.include?("Safari") || @renderer.include?("Safari") || @detail.include?("iPhone") || @identifier.include?("iPhone") @browser = "Safari" identifier_sub = nil @identifier.gsub(/[\\:\?'"%!@#\$\^&\*\(\)\+]/, '').split(" ").each do |ident| identifier_sub = ident.sub("Safari\/", "") if ident.include?("Safari") identifier_sub.gsub!(/[\+]/, '') if identifier_sub && identifier_sub.include?("+") end if identifier_sub == nil && @renderer.include?("Safari") renderer_gsub_gsub = @renderer.sub("\(", "").sub("\)", "") renderer_gsub_gsub.strip.split(",").each do |sec| identifier_sub = sec.sub("Safari\/", "").strip if sec.include?("Safari") end end SafariSpecialCases.each do |k, v| version_numbers = k.gsub(",", ".").split(".") v.each do |num| if identifier_sub == num @version.update(*version_numbers) end break if @version.major end # Special case 58.8 - check WebKit numbers # Special case 312 - check AppleWebKit # Special case 419.3 - could me mobile v3 check AppleWebKit for 420+ engine_id = @engine[/AppleWebKit\/([0-9.]+)/, 1] case identifier_sub when "85.8" case engine_id when '125.2' then @version.update('1', '2', '2') end when "125" case engine_id when '125.5.5' then @version.update('1', '2', '4') when '124' then @version.update('1', '2') when '312.5.2' then @version.update('1', '3', '1') when '312.1' then @version.update('1', '3') end when '412.5' case engine_id when '416.12' then @version.update('2','0','2') end when '416.13' case engine_id when '417.9' then @version.update('2','0','3') end when '412.2' case engine_id when '412.6' then @version.update('2','0') end when '312.3.1' case engine_id when '312.1' then @version.update('1', '3') when '312.5.1' then @version.update('1', '3', '1') end when "125.8" case engine_id when '312.5.1' then @version.update('1', '3', '1') when '125.2' then @version.update('1', '2', '2') end when "125.9" case engine_id when '125.4' then @version.update('1', '2', '3') when '125.5' then @version.update('1', '2', '3') when '312.5.1' then @version.update('1', '3', '1') end when "312" case engine_id when '416.11' then @version.update('2', '0', '2') end when "312.3.3" case engine_id when '312.8' then @version.update('1', '3', '2') end when "419.3" case engine_id when "420" then @version.update('3', '0') end end if (identifier_sub == "Safari") || (@identifier == "Safari/")then case engine_id when "418.9", "418.8" @version.update('2', '0', '4') end end ident_sub = nil if @identifier.include?("Version") then @identifier.split(" ").each do |ident| ident_sub = ident.sub("Version\/", "") if ident.include?("Version") if ident_sub then @version.update(*ident_sub.split(/[.,]/)) end end end if @identifier == "Safari/412 Privoxy/3.0" then @version.major = '2' @version.minor = '0' @version.sub = nil end break if @version.major end end if @browser == nil && @os.osx? && agent_string.include?("AppleWebKit") @browser = "Safari" end end |