Class: PlatformAgent

Inherits:
Object
  • Object
show all
Defined in:
lib/platform_agent.rb

Instance Method Summary collapse

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

Returns:

  • (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

Returns:

  • (Boolean)


68
69
70
# File 'lib/platform_agent.rb', line 68

def android_app?
  false
end

#android_phone?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/platform_agent.rb', line 26

def android_phone?
  !android_app? && android?
end

#app_versionObject



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

Returns:

  • (Boolean)


10
11
12
# File 'lib/platform_agent.rb', line 10

def desktop?
  !mobile?
end

#desktop_app?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


63
64
65
# File 'lib/platform_agent.rb', line 63

def ios_app?
  false
end

#ipad?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/platform_agent.rb', line 38

def ipad?
  match? /iPad/
end

#ipad_app?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/platform_agent.rb', line 58

def ipad_app?
  ipad? && ios_app?
end

#iphone?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/platform_agent.rb', line 22

def iphone?
  match? /iPhone/
end

#iphone_app?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


77
78
79
# File 'lib/platform_agent.rb', line 77

def mac_app?
  false
end

#missing?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/platform_agent.rb', line 86

def missing?
  user_agent_string.nil?
end

#mobile?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/platform_agent.rb', line 14

def mobile?
  phone? || tablet? || mobile_app?
end

#mobile_app?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/platform_agent.rb', line 50

def mobile_app?
  ios_app? || android_app?
end

#native_app?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/platform_agent.rb', line 46

def native_app?
  mobile_app? || desktop_app?
end

#other_phones?Boolean

Returns:

  • (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

Returns:

  • (Boolean)


18
19
20
# File 'lib/platform_agent.rb', line 18

def phone?
  iphone? || android? || other_phones?
end

#tablet?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/platform_agent.rb', line 34

def tablet?
  ipad? || match?(/(Kindle|Silk)/)
end

#to_sObject



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

Returns:

  • (Boolean)


82
83
84
# File 'lib/platform_agent.rb', line 82

def windows_app?
  false
end