Class: UserAgent
Constant Summary collapse
- UA_REGEXP =
%r{([^ /]+)/([^ ]+)(?: \(([^)]+)\))?}
Instance Method Summary collapse
- #android1? ⇒ Boolean
- #android2? ⇒ Boolean
- #android? ⇒ Boolean
- #blackberry? ⇒ Boolean
-
#body_class ⇒ Object
Returns the list of applicable browser features.
- #chrome? ⇒ Boolean
- #gecko20? ⇒ Boolean
- #gecko30? ⇒ Boolean
- #gecko35? ⇒ Boolean
- #gecko36? ⇒ Boolean
-
#gecko40? ⇒ Boolean
Different Firefox versions.
- #gecko? ⇒ Boolean
- #gecko_old? ⇒ Boolean
- #gecko_version?(from, to) ⇒ Boolean
- #ie6? ⇒ Boolean
- #ie7? ⇒ Boolean
- #ie8? ⇒ Boolean
-
#ie9? ⇒ Boolean
IE.
- #ie? ⇒ Boolean
-
#initialize(ua) ⇒ UserAgent
constructor
A new instance of UserAgent.
- #ios? ⇒ Boolean
- #ipad? ⇒ Boolean
- #iphone? ⇒ Boolean
-
#linux? ⇒ Boolean
OS’s and devices.
- #mac? ⇒ Boolean
- #nokia? ⇒ Boolean
- #opera? ⇒ Boolean
- #osx? ⇒ Boolean
- #rim? ⇒ Boolean
- #safari? ⇒ Boolean
-
#webkit? ⇒ Boolean
Browsers.
- #windows? ⇒ Boolean
Constructor Details
#initialize(ua) ⇒ UserAgent
Returns a new instance of UserAgent.
37 38 39 40 41 42 43 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 37 def initialize(ua) @ua_string = ua @ua = ua.scan(UA_REGEXP).map { |r| r[2] = r[2].split(';').map { |s| s.strip } unless r[2].nil? { :product => r[0], :version => r[1], :details => r[2] } } end |
Instance Method Details
#android1? ⇒ Boolean
59 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 59 def android1?() detail?(/^Android 1\./, 'Mozilla'); end |
#android2? ⇒ Boolean
60 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 60 def android2?() detail?(/^Android 2\./, 'Mozilla'); end |
#android? ⇒ Boolean
58 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 58 def android?() detail?(/^Android/, 'Mozilla'); end |
#blackberry? ⇒ Boolean
66 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 66 def blackberry?() detail?(/^Blackberry/, 'Mozilla'); end |
#body_class ⇒ Object
Returns the list of applicable browser features.
Examples
<body class="<%= browser.body_class %>">
This can return one of the following:
<body class="ios webkit ipad">
<body class="chrome linux webkit">
<body class="gecko linux">
<body class="windows ie ie6">
102 103 104 105 106 107 108 109 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 102 def body_class (%w(webkit chrome safari ios gecko opera ie linux) + %w(blackberry nokia android iphone) + %w(gecko36 gecko35 gecko30 gecko20 gecko_old) + %w(ipad windows osx mac ie6 ie7 ie8 ie9)).map do |aspect| aspect if self.send :"#{aspect}?" end.compact.join(' ') end |
#chrome? ⇒ Boolean
47 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 47 def chrome?() product?('Chrome'); end |
#gecko20? ⇒ Boolean
79 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 79 def gecko20?() gecko_version?(20061010, 20080610); end |
#gecko30? ⇒ Boolean
78 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 78 def gecko30?() gecko_version?(20080610, 20090612); end |
#gecko35? ⇒ Boolean
77 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 77 def gecko35?() gecko_version?(20090612, 20091111); end |
#gecko36? ⇒ Boolean
76 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 76 def gecko36?() gecko_version?(20091111, 20100401); end |
#gecko40? ⇒ Boolean
Different Firefox versions
75 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 75 def gecko40?() gecko_version?(20100401, 20110101); end |
#gecko? ⇒ Boolean
50 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 50 def gecko?() product?('Gecko'); end |
#gecko_old? ⇒ Boolean
80 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 80 def gecko_old?() gecko_version?(0, 20061010); end |
#gecko_version?(from, to) ⇒ Boolean
82 83 84 85 86 87 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 82 def gecko_version?(from, to) g = product('Gecko') return nil if g.nil? v = g[:version][0...8].to_i (v >= from) and (v < to) end |
#ie6? ⇒ Boolean
72 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 72 def ie6?() detail?(/^MSIE 6/, 'Mozilla'); end |
#ie7? ⇒ Boolean
71 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 71 def ie7?() detail?(/^MSIE 7.0/, 'Mozilla'); end |
#ie8? ⇒ Boolean
70 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 70 def ie8?() detail?('MSIE 8.0', 'Mozilla'); end |
#ie9? ⇒ Boolean
IE
69 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 69 def ie9?() detail?('MSIE 9.0', 'Mozilla'); end |
#ie? ⇒ Boolean
52 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 52 def ie?() detail?(/^MSIE/, 'Mozilla'); end |
#ios? ⇒ Boolean
49 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 49 def ios?() product?('Safari') && product?('Mobile'); end |
#ipad? ⇒ Boolean
62 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 62 def ipad?() detail?(/^iPad/, 'Mozilla'); end |
#iphone? ⇒ Boolean
56 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 56 def iphone?() detail?(/^iPhone/, 'Mozilla'); end |
#linux? ⇒ Boolean
OS’s and devices
55 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 55 def linux?() detail?(/^Linux/, 'Mozilla'); end |
#mac? ⇒ Boolean
65 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 65 def mac?() detail?(/^Macintosh/, 'Mozilla') || osx?; end |
#nokia? ⇒ Boolean
61 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 61 def nokia?() detail?(/^Nokia/, 'Mozilla') || detail?(/^Series[38]0/, 'Mozilla'); end |
#opera? ⇒ Boolean
51 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 51 def opera?() product?('Opera'); end |
#osx? ⇒ Boolean
64 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 64 def osx?() detail?(/^(Intel )?Mac OS X/, 'Mozilla'); end |
#rim? ⇒ Boolean
57 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 57 def rim?() detail?(/^Blackberry/, 'Mozilla'); end |
#safari? ⇒ Boolean
48 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 48 def safari?() product?('Safari') && !chrome?; end |
#webkit? ⇒ Boolean
Browsers
46 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 46 def webkit?() product?('AppleWebKit'); end |
#windows? ⇒ Boolean
63 |
# File 'lib/sinatra/support/useragenthelpers.rb', line 63 def windows?() detail?(/^Windows/, 'Mozilla'); end |