Class: AgentOrange::Engine
- Inherits:
-
Base
- Object
- Base
- AgentOrange::Engine
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
Instance Attribute Details
17
18
19
|
# File 'lib/agent_orange/engine.rb', line 17
def browser
@browser
end
|
#name ⇒ String
Returns one of the values from ENGINES.
11
12
13
|
# File 'lib/agent_orange/engine.rb', line 11
def name
@name
end
|
#type ⇒ Symbol
Returns one of the keys from ENGINES.
8
9
10
|
# File 'lib/agent_orange/engine.rb', line 8
def type
@type
end
|
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
populate(content)
elsif content[:comment] =~ /(#{ENGINES.collect{|cat,regex| regex}.join(')|(')})/i
chosen_content = { :name => nil, :version => nil }
additional_groups = (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
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_s ⇒ String
66
67
68
|
# File 'lib/agent_orange/engine.rb', line 66
def to_s
[name, version].compact.join(' ') || "Unknown"
end
|