Module: Jpmobile::RequestWithMobile

Included in:
Rack::Request
Defined in:
lib/jpmobile/request_with_mobile.rb

Instance Method Summary collapse

Instance Method Details

#mobileObject

携帯電話の機種に応じて Mobile::xxx を返す。携帯電話でない場合はnilを返す。



49
50
51
# File 'lib/jpmobile/request_with_mobile.rb', line 49

def mobile
  env['rack.jpmobile']
end

#mobile?Boolean

携帯電話からであれば trueを、そうでなければ false を返す。

Returns:

  • (Boolean)


33
34
35
# File 'lib/jpmobile/request_with_mobile.rb', line 33

def mobile?
  mobile and !mobile.smart_phone?
end

#remote_addrObject

for reverse proxy.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jpmobile/request_with_mobile.rb', line 13

def remote_addr
  if respond_to?(:remote_ip)
    __send__(:remote_ip)  # for Rails
  elsif respond_to?(:ip)
    __send__(:ip)         # for Rack
  else
    if env['HTTP_X_FORWARDED_FOR']
      env['HTTP_X_FORWARDED_FOR'].split(',').pop
    else
      env['REMOTE_ADDR']
    end
  end
end

#smart_phone?Boolean

スマートフォンであれば trueを、そうでなければ false を返す。

Returns:

  • (Boolean)


38
39
40
# File 'lib/jpmobile/request_with_mobile.rb', line 38

def smart_phone?
  mobile and mobile.smart_phone?
end

#tablet?Boolean

タブレットからであれば trueを、そうでなければ false を返す

Returns:

  • (Boolean)


43
44
45
# File 'lib/jpmobile/request_with_mobile.rb', line 43

def tablet?
  mobile and mobile.tablet?
end

#user_agentObject

環境変数 HTTP_USER_AGENT を返す。



8
9
10
# File 'lib/jpmobile/request_with_mobile.rb', line 8

def user_agent
  env['HTTP_USER_AGENT']
end

#user_agent=(str) ⇒ Object

環境変数 HTTP_USER_AGENT を設定する。



28
29
30
# File 'lib/jpmobile/request_with_mobile.rb', line 28

def user_agent=(str)
  self.env['HTTP_USER_AGENT'] = str
end