File: playstation.rb

package info (click to toggle)
ruby-useragent 0.16.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 164 kB
  • sloc: ruby: 1,150; makefile: 2
file content (80 lines) | stat: -rw-r--r-- 2,620 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
class UserAgent
  module Browsers
    # Mozilla/5.0 (PLAYSTATION 3 4.75) AppleWebKit/531.22.8 (KHTML, like Gecko)
    # Mozilla/5.0 (PLAYSTATION 3 4.76) AppleWebKit/531.22.8 (KHTML, like Gecko)
    # Mozilla/5.0 (PLAYSTATION 3; 1.00)
    # Mozilla/5.0 (PlayStation Vita 3.52) AppleWebKit/537.73 (KHTML, like Gecko) Silk/3.2
    # Mozilla/5.0 (PlayStation 4 2.57) AppleWebKit/537.73 (KHTML, like Gecko)
    class PlayStation < Base
      def self.extend?(agent)
        !agent.application.nil? && !agent.application.comment.nil? && agent.application.comment.any? && (
          agent.application.comment.first.include?('PLAYSTATION 3') ||
          agent.application.comment.first.include?('PlayStation Vita') ||
          agent.application.comment.first.include?('PlayStation 4')
        )
      end

      # Returns the name of the browser in use.
      # 
      # @return [nil, String] the name of the browser
      def browser
        if application.comment.first.include?('PLAYSTATION 3')
          'PS3 Internet Browser'
        elsif last.product == 'Silk'
          'Silk'
        elsif application.comment.first.include?('PlayStation 4')
          'PS4 Internet Browser'
        else
          nil
        end
      end

      # PS Vita is mobile, others are not.
      # 
      # @return [true, false] is this a mobile browser?
      def mobile?
        platform == 'PlayStation Vita'
      end

      # Returns the operating system in use.
      # 
      # @return [String] the operating system in use
      def os
        application.comment.join(' ')
      end

      # Returns the platform in use.
      # 
      # @return [nil, "PlayStation 3", "PlayStation 4", "PlayStation Vita"] the platform in use
      def platform
        if os.include?('PLAYSTATION 3')
          'PlayStation 3'
        elsif os.include?('PlayStation 4')
          'PlayStation 4'
        elsif os.include?('PlayStation Vita')
          'PlayStation Vita'
        else
          nil
        end
      end

      # Returns the browser version in use. If Silk, returns the version of Silk.
      # Otherwise, returns the PS3/PS4 firmware version.
      # 
      # @return [nil, Version] the version
      def version
        if browser == 'Silk'
          last.version
        elsif platform == 'PlayStation 3'
          Version.new(os.split('PLAYSTATION 3 ').last)
        elsif platform == 'PlayStation 4'
          Version.new(os.split('PlayStation 4 ').last)
        elsif platform == 'PlayStation Vita'
          Version.new(os.split('PlayStation Vita ').last)
        else
          nil
        end
      end
    end
  end
end