Class: AgentOrange::OperatingSystem
- Defined in:
- lib/agent_orange/operating_system.rb
Constant Summary collapse
- OPERATING_SYSTEMS =
{ :android => 'android', :freebsd => 'freebsd', :ios => 'iphone|ipad|ipod', :linux => 'linux', :netbsd => 'netbsd', :osx => 'osx|os x', :windows => 'windows' }
- OPERATING_SYSTEM_NAMES =
{ :android => 'Android', :freebsd => 'FreeBSD', :ios => 'Apple iOS', :linux => 'Linux', :netbsd => 'NetBSD', :osx => 'Mac OS X', :windows => 'Windows' }
Instance Attribute Summary collapse
-
#name ⇒ String
One of the values from OPERATING_SYSTEM_NAMES.
-
#type ⇒ Symbol
One of the keys from OPERATING_SYSTEMS.
- #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 OPERATING_SYSTEM_NAMES.
9 10 11 |
# File 'lib/agent_orange/operating_system.rb', line 9 def name @name end |
#type ⇒ Symbol
Returns one of the keys from OPERATING_SYSTEMS.
6 7 8 |
# File 'lib/agent_orange/operating_system.rb', line 6 def type @type end |
#version ⇒ AgentOrange::Version
12 13 14 |
# File 'lib/agent_orange/operating_system.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 47 48 49 50 51 52 53 54 |
# File 'lib/agent_orange/operating_system.rb', line 34 def parse(user_agent) AgentOrange.debug "OPERATING SYSTEM PARSING", 2 groups = parse_user_agent_string_into_groups(user_agent) groups.each_with_index do |content,i| if content[:comment] =~ /(#{OPERATING_SYSTEMS.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] =~ /(#{OPERATING_SYSTEMS.collect{|cat,regex| regex}.join(')|(')})/i chosen_content = additional_content end end populate(chosen_content) end end analysis end |
#populate(content = {}) ⇒ OperatingSystem
57 58 59 60 61 62 63 64 65 |
# File 'lib/agent_orange/operating_system.rb', line 57 def populate(content={}) debug_raw_content(content) AgentOrange.debug "", 2 self.type = determine_type(OPERATING_SYSTEMS, content[:name]) self.name = OPERATING_SYSTEM_NAMES[type.to_sym] self.version = AgentOrange::Version.new(content[:version]) self end |
#to_s ⇒ String
68 69 70 |
# File 'lib/agent_orange/operating_system.rb', line 68 def to_s [name, version].compact.join(' ') end |