Class: AgentOrange::Base
- Inherits:
-
Object
show all
- Defined in:
- lib/agent_orange/base.rb
Instance Method Summary
collapse
Constructor Details
#initialize(user_agent) ⇒ Base
Returns a new instance of Base.
4
5
6
|
# File 'lib/agent_orange/base.rb', line 4
def initialize(user_agent)
parse(user_agent)
end
|
Instance Method Details
#analysis ⇒ Object
64
65
66
67
68
|
# File 'lib/agent_orange/base.rb', line 64
def analysis
AgentOrange.debug self.class.name.upcase + ' ANALYSIS', 2
debug_content(:type => type, :name => name, :version => version)
AgentOrange.debug '', 2
end
|
#debug_content(content) ⇒ Object
#debug_raw_content(content) ⇒ Object
52
53
54
55
56
|
# File 'lib/agent_orange/base.rb', line 52
def debug_raw_content(content)
AgentOrange.debug " Raw Name : #{content[:name]}", 2
AgentOrange.debug " Raw Version: #{content[:version]}", 2
AgentOrange.debug " Raw Comment: #{content[:comment]}", 2
end
|
#determine_type(types = {}, content = "") ⇒ String
42
43
44
45
46
47
48
49
50
|
# File 'lib/agent_orange/base.rb', line 42
def determine_type(types={}, content="")
type = nil
types.each do |key, value|
type = key if content =~ /(#{value})/i
end
type = "other" if type.nil?
type
end
|
#parse(user_agent) ⇒ Object
8
9
10
|
# File 'lib/agent_orange/base.rb', line 8
def parse(user_agent)
raise 'Any class that extends AgentOrange::Base must implement parse(user_agent)'
end
|
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/agent_orange/base.rb', line 25
def ()
groups = []
.split('; ').each do |piece|
content = { :name => nil, :version => nil }
piece = piece.scan(/(.+) like .+$/i)[0][0] if piece =~ /(.+) like (.+)$/i
if piece =~ /(.+)[ \/]([\w.]+)$/i
chopped = piece.scan(/(.+)[ \/]([\w.]+)$/i)[0]
groups << { :name => chopped[0], :version => chopped[1] }
end
end
groups
end
|
#parse_user_agent_string_into_groups(user_agent) ⇒ Array
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/agent_orange/base.rb', line 13
def parse_user_agent_string_into_groups(user_agent)
results = user_agent.scan(/([^\/[:space:]]*)(\/([^[:space:]]*))?([[:space:]]*\[[a-zA-Z][a-zA-Z]\])?[[:space:]]*(\((([^()]|(\([^()]*\)))*)\))?[[:space:]]*/i)
groups = []
results.each do |result|
if result[0] != "" groups << { :name => result[0], :version => result[2], :comment => result[5] }
end
end
groups
end
|