Module: UserAgent

Defined in:
lib/useragent2css.rb,
lib/useragent2css/version.rb

Constant Summary collapse

VERSION =
'1.3.2'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.css(ua) ⇒ Object



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
# File 'lib/useragent2css.rb', line 5

def self.css(ua)
  ua = (ua||"").downcase
  br = case ua
    when /opera[\/,\s+](\d+)/
      o = %W(opera opera#{$1})
      o << "mobile" if ua.include?('mini')
      o.join(" ")
    when /webtv/ ;              "gecko"
    when /msie (\d+)/ ;         "ie ie#{$1}"
    when /rv\:(\d\d)\./ ;       "gecko ie#{$1}"
    when %r{firefox/2} ;        "gecko ff2"
    when %r{firefox/3.5} ;      "gecko ff3 ff3_5"
    when %r{firefox/3} ;        "gecko ff3"
    when %r{firefox/4} ;        "gecko ff4"
    when /konqueror/ ;          "konqueror"
    when /applewebkit\/([\d.]+).? \([^)]*\) ?(?:version\/(\d+))?.*$/
      o = %W(webkit)
      if ua.include?('iron')
        o << 'iron'
      elsif ua.include?('chrome')
        ua =~ /chrome\/(\d+)/
        o << "chrome chrome#{$1}"
      else
        o << "safari safari"+ ($2 || (($1.to_i >= 400) ? '2' : '1'))
      end
      o.join(" ")
    when /gecko/, /mozilla/ ;   "gecko"
  end
  br = (br.nil? ? "mobile" : "#{br} mobile") if ua.include?('mobile')
  os = ua.include?('mac') || ua.include?('darwin') ?
         ua.include?('iphone') ? 'iphone' : ua.include?('ipod') ? 'ipod' : ua.include?('ipad') ? 'ipad' : 'mac' :
       ua.include?('x11') || ua.include?('linux') ? 'linux' :
       ua.include?('win') ? 'win' : nil
  "#{br}#{" " unless br.nil? or os.nil?}#{os}"
end

Instance Method Details

#useragent2css(ua = request.env["HTTP_USER_AGENT"]) ⇒ Object



41
42
43
# File 'lib/useragent2css.rb', line 41

def useragent2css(ua = request.env["HTTP_USER_AGENT"])
  UserAgent.css(ua)
end