Class: AgentOrange::Browser
Constant Summary collapse
- BROWSERS =
{ :ie => 'MSIE|Internet Explorer|IE', :firefox => 'Firefox', :opera => 'Opera', :chrome => 'Chrome', :safari => 'Safari' }
- BROWSER_TITLES =
BROWSERS.merge :ie => 'MSIE'
Instance Attribute Summary collapse
-
#name ⇒ String
One of the values from BROWSERS.
-
#security ⇒ Object
Returns the value of attribute security.
-
#type ⇒ Symbol
One of the keys from BROWSERS.
- #version ⇒ AgentOrange::Version
Instance Method Summary collapse
Methods inherited from Base
#analysis, #debug_content, #debug_raw_content, #determine_type, #initialize, #parse_comment, #parse_user_agent_string_into_groups
Constructor Details
This class inherits a constructor from AgentOrange::Base
Instance Attribute Details
#name ⇒ String
Returns one of the values from BROWSERS.
10 11 12 |
# File 'lib/agent_orange/browser.rb', line 10 def name @name end |
#security ⇒ Object
Returns the value of attribute security.
15 16 17 |
# File 'lib/agent_orange/browser.rb', line 15 def security @security end |
#type ⇒ Symbol
Returns one of the keys from BROWSERS.
7 8 9 |
# File 'lib/agent_orange/browser.rb', line 7 def type @type end |
#version ⇒ AgentOrange::Version
13 14 15 |
# File 'lib/agent_orange/browser.rb', line 13 def version @version end |
Instance Method Details
#parse(user_agent) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/agent_orange/browser.rb', line 27 def parse(user_agent) AgentOrange.debug "BROWSER PARSING", 2 groups = parse_user_agent_string_into_groups(user_agent) groups.each_with_index do |content,i| if content[:name] =~ /(#{BROWSERS.collect{|cat,regex| regex}.join(')|(')})/i # Matched group against name self.populate(content) break elsif content[:comment] =~ /(#{BROWSERS.collect{|cat,regex| regex}.join(')|(')})/i # Matched group against comment chosen_content = { :name => nil, :version => nil } additional_groups = parse_comment(content[:comment]) additional_groups.each do |additional_content| if additional_content[:name] =~ /(#{BROWSERS.collect{|cat,regex| regex}.join(')|(')})/i chosen_content = additional_content #Additional checking for chromeframe, iemobile, etc. BROWSERS.each do |cat, regex| chosen_content[:name] = BROWSER_TITLES[cat] if additional_content[:name] =~ /(#{regex})/i end end end populate(chosen_content) end end analysis end |
#populate(content = {}) ⇒ Browser
59 60 61 62 63 64 65 66 67 |
# File 'lib/agent_orange/browser.rb', line 59 def populate(content={}) debug_raw_content(content) AgentOrange.debug "", 2 self.type = determine_type(BROWSERS, content[:name]) self.name = content[:name] self.version = AgentOrange::Version.new(content[:version]) self end |
#to_s ⇒ String
70 71 72 |
# File 'lib/agent_orange/browser.rb', line 70 def to_s [name, version].compact.join(' ') end |