class PlatformAgent
Attributes
user_agent_string[RW]
Public Class Methods
new(user_agent_string)
click to toggle source
# File lib/platform_agent.rb, line 4 def initialize(user_agent_string) self.user_agent_string = user_agent_string end
Public Instance Methods
android?()
click to toggle source
# File lib/platform_agent.rb, line 42 def android? match? /Android/ end
android_app?()
click to toggle source
Must overwrite with app-specific match
# File lib/platform_agent.rb, line 68 def android_app? false end
android_phone?()
click to toggle source
# File lib/platform_agent.rb, line 26 def android_phone? !android_app? && android? end
app_version()
click to toggle source
# 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?()
click to toggle source
# File lib/platform_agent.rb, line 10 def desktop? !mobile? end
desktop_app?()
click to toggle source
# File lib/platform_agent.rb, line 72 def desktop_app? mac_app? || windows_app? end
ios_app?()
click to toggle source
Must overwrite with app-specific match
# File lib/platform_agent.rb, line 63 def ios_app? false end
ipad?()
click to toggle source
# File lib/platform_agent.rb, line 38 def ipad? match? /iPad/ end
ipad_app?()
click to toggle source
# File lib/platform_agent.rb, line 58 def ipad_app? ipad? && ios_app? end
iphone?()
click to toggle source
# File lib/platform_agent.rb, line 22 def iphone? match? /iPhone/ end
iphone_app?()
click to toggle source
# File lib/platform_agent.rb, line 54 def iphone_app? iphone? && ios_app? end
mac_app?()
click to toggle source
Must overwrite with app-specific match
# File lib/platform_agent.rb, line 77 def mac_app? false end
missing?()
click to toggle source
# File lib/platform_agent.rb, line 86 def missing? user_agent_string.nil? end
mobile?()
click to toggle source
# File lib/platform_agent.rb, line 14 def mobile? phone? || tablet? || mobile_app? end
mobile_app?()
click to toggle source
# File lib/platform_agent.rb, line 50 def mobile_app? ios_app? || android_app? end
native_app?()
click to toggle source
# File lib/platform_agent.rb, line 46 def native_app? mobile_app? || desktop_app? end
other_phones?()
click to toggle source
# File lib/platform_agent.rb, line 30 def other_phones? match? /(iPod|Windows Phone|BlackBerry|BB10.*Mobile|Mobile.*Firefox)/ end
phone?()
click to toggle source
# File lib/platform_agent.rb, line 18 def phone? iphone? || android? || other_phones? end
tablet?()
click to toggle source
# File lib/platform_agent.rb, line 34 def tablet? ipad? || match?(/(Kindle|Silk)/) end
to_s()
click to toggle source
# 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?()
click to toggle source
Must overwrite with app-specific match
# File lib/platform_agent.rb, line 82 def windows_app? false end
Private Instance Methods
match?(pattern)
click to toggle source
# File lib/platform_agent.rb, line 112 def match?(pattern) user_agent_string.to_s.match?(pattern) end
user_agent()
click to toggle source
# File lib/platform_agent.rb, line 116 def user_agent @user_agent ||= UserAgent.parse(user_agent_string) end