Class: UserAgentParser
- Inherits:
-
Object
- Object
- UserAgentParser
- Defined in:
- app/my_lib/user_agent_parser.rb
Overview
typed: ignore
Instance Attribute Summary collapse
-
#user_agent ⇒ Object
readonly
Returns the value of attribute user_agent.
Instance Method Summary collapse
- #android? ⇒ Boolean
- #app? ⇒ Boolean
-
#initialize(user_agent) ⇒ UserAgentParser
constructor
A new instance of UserAgentParser.
- #ios? ⇒ Boolean
- #platform ⇒ Object
- #to_s ⇒ Object
- #web? ⇒ Boolean
Constructor Details
#initialize(user_agent) ⇒ UserAgentParser
Returns a new instance of UserAgentParser.
6 7 8 |
# File 'app/my_lib/user_agent_parser.rb', line 6 def initialize(user_agent) @user_agent = user_agent.downcase end |
Instance Attribute Details
#user_agent ⇒ Object (readonly)
Returns the value of attribute user_agent.
4 5 6 |
# File 'app/my_lib/user_agent_parser.rb', line 4 def user_agent @user_agent end |
Instance Method Details
#android? ⇒ Boolean
20 21 22 |
# File 'app/my_lib/user_agent_parser.rb', line 20 def android? @_android ||= app? && @user_agent.match(/android/i).present? end |
#app? ⇒ Boolean
28 29 30 |
# File 'app/my_lib/user_agent_parser.rb', line 28 def app? @_app ||= present? && @user_agent.match(/hh partner/i).present? end |
#ios? ⇒ Boolean
24 25 26 |
# File 'app/my_lib/user_agent_parser.rb', line 24 def ios? @_ios ||= app? && @user_agent.match(/ios/i).present? end |
#platform ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'app/my_lib/user_agent_parser.rb', line 10 def platform if web? 'website' elsif android? 'android-app' elsif ios? 'ios-app' end end |
#to_s ⇒ Object
36 37 38 |
# File 'app/my_lib/user_agent_parser.rb', line 36 def to_s @user_agent end |
#web? ⇒ Boolean
32 33 34 |
# File 'app/my_lib/user_agent_parser.rb', line 32 def web? @_web ||= present? && !app? end |