Class: AgentHelpers::Detector

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_helpers/detector.rb

Constant Summary collapse

WINDOWS_VERSIONS =
{
  "NT 5.0" => "Windows 2000",
  "NT 5.01" => "Windows 2000 SP1",
  "NT 5.1" => "Windows XP",
  "NT 5.2" => "Windows XP 64bit",
  "NT 6.0" => "Windows Vista",
  "NT 6.1" => "Windows 7",
  "NT 6.2" => "Windows 8",
  "NT 6.3" => "Windows 8.1"
}
MAC_OSX_VERSIONS =
{
  "10.0" => "Cheetah",
  "10.1" => "Puma",
  "10.2" => "Juguar",
  "10.3" => "Panther",
  "10.4" => "Tiger",
  "10.5" => "Leopard",
  "10.6" => "Snow Leopard",
  "10.7" => "Lion",
  "10.8" => "Mountain Lion",
  "10.9" => "Mavericks",
  "10.10" => "Yosemite"
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Detector

Returns a new instance of Detector.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agent_helpers/detector.rb', line 29

def initialize(args)
  @request = args[:request]
  raise "No request was given." unless @request
  @env = @request.env
  @user_agent = @request.user_agent.to_s.downcase.strip
  raise "No user agent was given." if @user_agent.empty?

  browsers = [:chrome, :ie, :firefox, :opera, :safari]
  browsers.each do |browser|
    __send__("parse_#{browser}") unless @browser
  end

  parse_bots unless @browser
  parse_device
end

Instance Attribute Details

#browserObject (readonly)

Returns the value of attribute browser.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def browser
  @browser
end

#deviceObject (readonly)

Returns the value of attribute device.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def device
  @device
end

#osObject (readonly)

Returns the value of attribute os.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def os
  @os
end

#os_titleObject (readonly)

Returns the value of attribute os_title.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def os_title
  @os_title
end

#os_versionObject (readonly)

Returns the value of attribute os_version.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def os_version
  @os_version
end

#titleObject (readonly)

Returns the value of attribute title.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def title
  @title
end

#versionObject (readonly)

Returns the value of attribute version.



2
3
4
# File 'lib/agent_helpers/detector.rb', line 2

def version
  @version
end

Instance Method Details

#version_majorObject



45
46
47
48
49
50
51
# File 'lib/agent_helpers/detector.rb', line 45

def version_major
  if match = version.to_s.match(/^(\d+)/)
    return match[1].to_i
  else
    return nil
  end
end