Module: RubyNative::NativeDetection
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/ruby_native/native_detection.rb
Constant Summary collapse
- SIGNATURE =
Matches "Ruby Native iOS/5.2/35 iOS/26.5.2/23F79 RubyNative/0.12.5". The build, OS, and OS build groups are optional: apps built before the UA carried them send only "Ruby Native iOS/5.2" (or later "... iOS/26.5.2" without the OS build), and the optional groups keep the OS capture from swallowing the app version.
%r{Ruby Native (?:iOS|Android)/([\d.]+)(?:/([\d.]+) (?:iOS|Android)/([\d.]+)(?:/([\w.]+))?)?}
Instance Method Summary collapse
- #native_app? ⇒ Boolean
-
#native_app_build ⇒ Object
The app's build number (CFBundleVersion / versionCode), like "35".
-
#native_app_version ⇒ Object
The app's marketing version, like "5.2".
-
#native_os_build ⇒ Object
The device's OS build, like "23F79" (iOS) or "UQ1A.240205.004" (Android).
-
#native_os_version ⇒ Object
The device's OS version, like "26.5.2".
-
#native_platform ⇒ Object
Returns "ios" or "android" for native requests, nil for web browsers.
- #native_version ⇒ Object
Instance Method Details
#native_app? ⇒ Boolean
19 20 21 |
# File 'lib/ruby_native/native_detection.rb', line 19 def native_app? request.user_agent.to_s.include?("Ruby Native") end |
#native_app_build ⇒ Object
The app's build number (CFBundleVersion / versionCode), like "35". Nil for web browsers and apps built before the User-Agent carried it.
44 45 46 |
# File 'lib/ruby_native/native_detection.rb', line 44 def native_app_build request.user_agent.to_s[SIGNATURE, 2] end |
#native_app_version ⇒ Object
The app's marketing version, like "5.2". Nil for web browsers.
38 39 40 |
# File 'lib/ruby_native/native_detection.rb', line 38 def native_app_version request.user_agent.to_s[SIGNATURE, 1] end |
#native_os_build ⇒ Object
The device's OS build, like "23F79" (iOS) or "UQ1A.240205.004" (Android). Nil for web browsers and apps built before the User-Agent carried it.
56 57 58 |
# File 'lib/ruby_native/native_detection.rb', line 56 def native_os_build request.user_agent.to_s[SIGNATURE, 4] end |
#native_os_version ⇒ Object
The device's OS version, like "26.5.2". Nil for web browsers and apps built before the User-Agent carried it.
50 51 52 |
# File 'lib/ruby_native/native_detection.rb', line 50 def native_os_version request.user_agent.to_s[SIGNATURE, 3] end |
#native_platform ⇒ Object
Returns "ios" or "android" for native requests, nil for web browsers.
Used by view helpers to pick the right icon from icons: { ios:, android: }.
30 31 32 33 34 35 |
# File 'lib/ruby_native/native_detection.rb', line 30 def native_platform ua = request.user_agent.to_s return "ios" if ua.include?("Ruby Native iOS") return "android" if ua.include?("Ruby Native Android") nil end |
#native_version ⇒ Object
23 24 25 26 |
# File 'lib/ruby_native/native_detection.rb', line 23 def native_version match = request.user_agent.to_s.match(/RubyNative\/([\d.]+)/) NativeVersion.new(match ? match[1] : "0") end |