Class: AgentOrange::Platform
- Inherits:
-
Base
- Object
- Base
- AgentOrange::Platform
show all
- Defined in:
- lib/agent_orange/platform.rb
Constant Summary
collapse
- PLATFORMS =
{
:android => 'android',
:apple => 'iphone|ipad|ipod',
:mac => 'macintosh',
:pc => 'freebsd|linux|netbsd|windows|x11'
}
- PLATFORM_NAMES =
{
:android => 'Android',
:apple => 'Apple',
:mac => 'Macintosh',
:pc => 'PC'
}
- PLATFORM_VERSIONS =
{
:ipad => 'ipad',
:iphone => 'iphone',
:ipod => 'ipod'
}
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
#name ⇒ String
9
10
11
|
# File 'lib/agent_orange/platform.rb', line 9
def name
@name
end
|
#type ⇒ Symbol
6
7
8
|
# File 'lib/agent_orange/platform.rb', line 6
def type
@type
end
|
12
13
14
|
# File 'lib/agent_orange/platform.rb', line 12
def version
@version
end
|
Instance Method Details
#parse(user_agent) ⇒ Object
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/agent_orange/platform.rb', line 34
def parse(user_agent)
AgentOrange.debug "PLATFORM PARSING", 2
groups = parse_user_agent_string_into_groups(user_agent)
groups.each_with_index do |content,i|
if content[:comment] =~ /(#{PLATFORMS.collect{|cat,regex| regex}.join(')|(')})/i
populate(content)
end
end
analysis
end
|
#populate(content = {}) ⇒ Platform
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/agent_orange/platform.rb', line 49
def populate(content={})
debug_raw_content(content)
AgentOrange.debug "", 2
self.type = determine_type(PLATFORMS, content[:comment])
self.name = PLATFORM_NAMES[type.to_sym]
if type == :apple
self.version = case determine_type(PLATFORM_VERSIONS, content[:comment])
when :ipad
AgentOrange::Version.new("iPad")
when :iphone
AgentOrange::Version.new("iPhone")
when :ipod
AgentOrange::Version.new("iPod")
else
AgentOrange::Version.new("Unknown")
end
else
self.version = nil
end
self
end
|
#to_s ⇒ Object
74
75
76
|
# File 'lib/agent_orange/platform.rb', line 74
def to_s
[name, version].compact.join(' ')
end
|