Class: AgentOrange::Engine

Inherits:
Base
  • Object
show all
Defined in:
lib/agent_orange/engine.rb

Constant Summary collapse

ENGINES =
{
  :gecko  => 'Gecko',
  :presto => 'Presto',
  :trident => 'Trident',
  :webkit => 'AppleWebKit',
  :other => 'Other'
}

Instance Attribute Summary collapse

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

#browserAgentOrange::Browser



17
18
19
# File 'lib/agent_orange/engine.rb', line 17

def browser
  @browser
end

#nameString

Returns one of the values from ENGINES.

Returns:

  • (String)

    one of the values from ENGINES



11
12
13
# File 'lib/agent_orange/engine.rb', line 11

def name
  @name
end

#typeSymbol

Returns one of the keys from ENGINES.

Returns:

  • (Symbol)

    one of the keys from ENGINES



8
9
10
# File 'lib/agent_orange/engine.rb', line 8

def type
  @type
end

#versionAgentOrange::Version



14
15
16
# File 'lib/agent_orange/engine.rb', line 14

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
# File 'lib/agent_orange/engine.rb', line 27

def parse(user_agent)
  AgentOrange.debug "ENGINE PARSING", 2

  groups = parse_user_agent_string_into_groups(user_agent)
  groups.each_with_index do |content,i|
    if content[:name] =~ /(#{ENGINES.collect{|cat,regex| regex}.join(')|(')})/i
      # Matched group against name
      populate(content)
    elsif content[:comment] =~ /(#{ENGINES.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] =~ /(#{ENGINES.collect{|cat,regex| regex}.join(')|(')})/i
          chosen_content = additional_content
        end
      end

      populate(chosen_content)
    end
  end

  analysis
  
  self.browser = AgentOrange::Browser.new(user_agent)
end

#populate(content = {}) ⇒ Engine

Returns:



55
56
57
58
59
60
61
62
63
# File 'lib/agent_orange/engine.rb', line 55

def populate(content={})
  debug_raw_content(content)
  AgentOrange.debug "", 2

  self.type = determine_type(ENGINES, content[:name])
  self.name = ENGINES[type.to_sym]
  self.version = AgentOrange::Version.new(content[:version])
  self
end

#to_sString

Returns:

  • (String)


66
67
68
# File 'lib/agent_orange/engine.rb', line 66

def to_s
  [name, version].compact.join(' ') || "Unknown"
end