Class: Rails_Agent_Detect

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

Class Method Summary collapse

Class Method Details

.is_mobileObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rails_agent_detect.rb', line 3

def self.is_mobile
  docomo        = "docomo"
  softbank      = "softbank"
  au            = "au"
  iphone        = "iphone"
  ipad          = "ipad"
  android       = "anroid"
  blackberry    = "blackberry"
  blackberry5   = "blackberry5"
  windowsphone  = "windowsphone"
  windowsphone7 = "windowsphone7"
  windowsphone8 = "windowsphone8"
  motorola      = "motorola"
  symbian       = "symbian"
  mobile        = "mobile"
  lg            = "lg"
  pc            = "pc"
  default       = "default"
  # url           = "http://#{request.host+request.fullpath}"
  # url1          = "http://#{request.host}:#{request.port}#{request.fullpath}"
  # link          = url1.gsub("#{request.host}:#{request.port}","#{request.host}:#{request.port}/m")
  # check_url     = "http://#{request.host}:#{request.port}\/m"
  user_agent = request.env['HTTP_USER_AGENT'].downcase if request.env['HTTP_USER_AGENT'].present?

  if (user_agent.to_s.match(/iphone/) || user_agent.to_s.match(/ipad/) || user_agent.to_s.match(/android/) || user_agent.to_s.match(/blackberry/) || user_agent.to_s.match(/blackberry5/) || user_agent.to_s.match(/windowsphone/) || user_agent.to_s.match(/windowsphone7/) || user_agent.to_s.match(/windowsphone8/) || user_agent.to_s.match(/motorola/) || user_agent.to_s.match(/symbian/))
    return true
    # if (user_agent.to_s.match(/ipad/))
    #   @@is_tablet = true
    # elsif (user_agent.to_s.match(/android/))
    #   if (user_agent.to_s.match(/mobile/))
    #     @@is_tablet = false
    #   else
    #     @@is_tablet = true
    #   end
    # end
    #redirect_to link unless url1.to_s.match(check_url.to_s)
  else
    return false
  end
end