File: wechat_browser.rb

package info (click to toggle)
ruby-useragent 0.16.8-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 368 kB
  • sloc: ruby: 4,824; makefile: 2
file content (44 lines) | stat: -rw-r--r-- 1,138 bytes parent folder | download | duplicates (3)
1
2
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
43
44
class UserAgent
  module Browsers
    class WechatBrowser < Base
      def self.extend?(agent)
        agent.detect { |useragent| useragent.product =~ /MicroMessenger/i }
      end

      def browser
        'Wechat Browser'
      end

      def version
        micro_messenger = detect_product("MicroMessenger")
        Version.new(micro_messenger.version)
      end

      def platform
        return unless application

        if application.comment[0] =~ /iPhone/
          'iPhone'
        elsif application.comment.any? { |c| c =~ /Android/ }
          'Android'
        else
          application.comment[0]
        end
      end

      def os
        return unless application

        if application.comment[0] =~ /Windows NT/
          OperatingSystems.normalize_os(application.comment[0])
        elsif application.comment[2].nil?
          OperatingSystems.normalize_os(application.comment[1])
        elsif application.comment[1] =~ /Android/
          OperatingSystems.normalize_os(application.comment[1])
        else
          OperatingSystems.normalize_os(application.comment[2])
        end
      end
    end
  end
end