Class: PlatformAgent
- Inherits:
-
Object
- Object
- PlatformAgent
- Defined in:
- lib/platform_agent.rb
Instance Method Summary collapse
- #android? ⇒ Boolean
-
#android_app? ⇒ Boolean
Must overwrite with app-specific match.
- #android_phone? ⇒ Boolean
- #app_version ⇒ Object
- #desktop? ⇒ Boolean
- #desktop_app? ⇒ Boolean
-
#initialize(user_agent_string) ⇒ PlatformAgent
constructor
A new instance of PlatformAgent.
-
#ios_app? ⇒ Boolean
Must overwrite with app-specific match.
- #ipad? ⇒ Boolean
- #ipad_app? ⇒ Boolean
- #iphone? ⇒ Boolean
- #iphone_app? ⇒ Boolean
-
#mac_app? ⇒ Boolean
Must overwrite with app-specific match.
- #missing? ⇒ Boolean
- #mobile? ⇒ Boolean
- #mobile_app? ⇒ Boolean
- #native_app? ⇒ Boolean
- #other_phones? ⇒ Boolean
- #phone? ⇒ Boolean
- #tablet? ⇒ Boolean
- #to_s ⇒ Object
-
#windows_app? ⇒ Boolean
Must overwrite with app-specific match.
Constructor Details
#initialize(user_agent_string) ⇒ PlatformAgent
Returns a new instance of PlatformAgent.
4 5 6 |
# File 'lib/platform_agent.rb', line 4 def initialize(user_agent_string) self.user_agent_string = user_agent_string end |
Instance Method Details
#android? ⇒ Boolean
42 43 44 |
# File 'lib/platform_agent.rb', line 42 def android? match? /Android/ end |
#android_app? ⇒ Boolean
Must overwrite with app-specific match
68 69 70 |
# File 'lib/platform_agent.rb', line 68 def android_app? false end |
#android_phone? ⇒ Boolean
26 27 28 |
# File 'lib/platform_agent.rb', line 26 def android_phone? !android_app? && android? end |
#app_version ⇒ Object
90 91 92 93 |
# File 'lib/platform_agent.rb', line 90 def app_version # App user-agent string is parsed into two separate UserAgent instances, it's the last one that contains the right version user_agent.last.version if native_app? end |
#desktop? ⇒ Boolean
10 11 12 |
# File 'lib/platform_agent.rb', line 10 def desktop? !mobile? end |
#desktop_app? ⇒ Boolean
72 73 74 |
# File 'lib/platform_agent.rb', line 72 def desktop_app? mac_app? || windows_app? end |
#ios_app? ⇒ Boolean
Must overwrite with app-specific match
63 64 65 |
# File 'lib/platform_agent.rb', line 63 def ios_app? false end |
#ipad? ⇒ Boolean
38 39 40 |
# File 'lib/platform_agent.rb', line 38 def ipad? match? /iPad/ end |
#ipad_app? ⇒ Boolean
58 59 60 |
# File 'lib/platform_agent.rb', line 58 def ipad_app? ipad? && ios_app? end |
#iphone? ⇒ Boolean
22 23 24 |
# File 'lib/platform_agent.rb', line 22 def iphone? match? /iPhone/ end |
#iphone_app? ⇒ Boolean
54 55 56 |
# File 'lib/platform_agent.rb', line 54 def iphone_app? iphone? && ios_app? end |
#mac_app? ⇒ Boolean
Must overwrite with app-specific match
77 78 79 |
# File 'lib/platform_agent.rb', line 77 def mac_app? false end |
#missing? ⇒ Boolean
86 87 88 |
# File 'lib/platform_agent.rb', line 86 def missing? user_agent_string.nil? end |
#mobile? ⇒ Boolean
14 15 16 |
# File 'lib/platform_agent.rb', line 14 def mobile? phone? || tablet? || mobile_app? end |
#mobile_app? ⇒ Boolean
50 51 52 |
# File 'lib/platform_agent.rb', line 50 def mobile_app? ios_app? || android_app? end |
#native_app? ⇒ Boolean
46 47 48 |
# File 'lib/platform_agent.rb', line 46 def native_app? mobile_app? || desktop_app? end |
#other_phones? ⇒ Boolean
30 31 32 |
# File 'lib/platform_agent.rb', line 30 def other_phones? match? /(iPod|Windows Phone|BlackBerry|BB10.*Mobile|Mobile.*Firefox)/ end |
#phone? ⇒ Boolean
18 19 20 |
# File 'lib/platform_agent.rb', line 18 def phone? iphone? || android? || other_phones? end |
#tablet? ⇒ Boolean
34 35 36 |
# File 'lib/platform_agent.rb', line 34 def tablet? ipad? || match?(/(Kindle|Silk)/) end |
#to_s ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/platform_agent.rb', line 95 def to_s case when ipad_app? then "iPad app" when iphone_app? then "iPhone app" when android_app? then "Android app" when mac_app? then "Mac app" when windows_app? then "Windows app" when tablet? then "tablet" when phone? then "phone" when missing? then "missing" else "web" end end |
#windows_app? ⇒ Boolean
Must overwrite with app-specific match
82 83 84 |
# File 'lib/platform_agent.rb', line 82 def windows_app? false end |