Object
Check for known browsers
# File lib/rackamole/utils/agent_detect.rb, line 22
22: def self.check?( agent, browser )
23: agent.match( /#{browser}/ )
24: end
Pre populate info hash
# File lib/rackamole/utils/agent_detect.rb, line 27
27: def self.defaults
28: info = { :browser => {}, :machine => {} }
29: ]name version].each { |t| info[:browser][t.to_sym] = "N/A" }
30: ]platform os version local].each { |t| info[:machine][t.to_sym] = "N/A" }
31: info
32: end
Extract machine and browser info
# File lib/rackamole/utils/agent_detect.rb, line 35
35: def self.extract( agent, browser )
36: @info = defaults
37: begin
38: extract_browser( agent, browser )
39: extract_platform( agent )
40: rescue => boom
41: $stderr.puts "Unable to parse user agent `#{agent}"
42: $stderr.puts boom
43: boom.backtrace.each { |l| $stderr.puts l }
44: end
45: @info
46: end
Extract browser and version
# File lib/rackamole/utils/agent_detect.rb, line 49
49: def self.extract_browser( agent, browser )
50: @info[:browser][:name] = browser
51: match = agent.match( /#{browser}[\/|\s]([\d|\.?]+)/ )
52: @info[:browser][:version] = match[1] if match and match[1]
53: end
Extracts machine info
# File lib/rackamole/utils/agent_detect.rb, line 56
56: def self.extract_platform( agent )
57: match = agent.match( /\((.*)\)/ )
58: return unless match and match[1]
59:
60: machine_info = match[1]
61: tokens = machine_info.split( ";" )
62: unless tokens.empty?
63: index = 1
64: platform = tokens[0].strip
65: @info[:machine][:platform] = platform
66:
67: index += 1 if tokens[1].match( /[MSIE|U]/ )
68: os = tokens[index].match( /(.+)\s([\w\d|\.]+)/ )
69: if os
70: @info[:machine][:os] = os[1].strip if os[1]
71: @info[:machine][:version] = os[2].strip if os[2]
72: end
73: end
74: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.