Class: Dommy::Navigator
- Inherits:
-
Object
- Object
- Dommy::Navigator
- Defined in:
- lib/dommy/navigator.rb
Overview
‘window.navigator` — exposes browser-agent metadata plus `clipboard` / `permissions` sub-objects. Dommy returns sensible defaults (Dommy as user agent, “en” language, online=true) that tests can override.
Constant Summary collapse
- DEFAULT_USER_AGENT =
"Mozilla/5.0 (Dommy) Ruby"
Instance Attribute Summary collapse
-
#clipboard ⇒ Object
readonly
Returns the value of attribute clipboard.
-
#cookie_enabled ⇒ Object
Returns the value of attribute cookie_enabled.
-
#geolocation ⇒ Object
readonly
Returns the value of attribute geolocation.
-
#language ⇒ Object
Returns the value of attribute language.
-
#languages ⇒ Object
Returns the value of attribute languages.
-
#locks ⇒ Object
readonly
Returns the value of attribute locks.
-
#on_line ⇒ Object
Returns the value of attribute on_line.
-
#permissions ⇒ Object
readonly
Returns the value of attribute permissions.
-
#platform ⇒ Object
Returns the value of attribute platform.
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#user_agent ⇒ Object
Returns the value of attribute user_agent.
-
#vendor ⇒ Object
Returns the value of attribute vendor.
-
#wake_lock ⇒ Object
readonly
Returns the value of attribute wake_lock.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(k, v) ⇒ Object
- #__js_call__(method, args) ⇒ Object
- #__js_get__(key) ⇒ Object
- #__js_set__(_key, _value) ⇒ Object
- #__last_shared__ ⇒ Object
- #__vibration_log__ ⇒ Object
- #can_share(_data = nil) ⇒ Object (also: #canShare)
-
#get_battery ⇒ Object
(also: #getBattery)
Battery Status API stub.
-
#initialize(window) ⇒ Navigator
constructor
A new instance of Navigator.
-
#share(data = nil) ⇒ Object
Web Share API.
-
#vibrate(pattern) ⇒ Object
Vibration API.
Constructor Details
#initialize(window) ⇒ Navigator
Returns a new instance of Navigator.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/dommy/navigator.rb', line 13 def initialize(window) @window = window @user_agent = DEFAULT_USER_AGENT @language = "en" @languages = ["en"].freeze @platform = "Dommy" @vendor = "Dommy" @on_line = true @cookie_enabled = true @clipboard = Clipboard.new(window) @permissions = Permissions.new(window) @geolocation = Geolocation.new(window) @vibration_log = [] @wake_lock = WakeLock.new(window) @locks = LockManager.new(window) @storage = StorageManager.new(window) end |
Instance Attribute Details
#clipboard ⇒ Object (readonly)
Returns the value of attribute clipboard.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def clipboard @clipboard end |
#cookie_enabled ⇒ Object
Returns the value of attribute cookie_enabled.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def @cookie_enabled end |
#geolocation ⇒ Object (readonly)
Returns the value of attribute geolocation.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def geolocation @geolocation end |
#language ⇒ Object
Returns the value of attribute language.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def language @language end |
#languages ⇒ Object
Returns the value of attribute languages.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def languages @languages end |
#locks ⇒ Object (readonly)
Returns the value of attribute locks.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def locks @locks end |
#on_line ⇒ Object
Returns the value of attribute on_line.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def on_line @on_line end |
#permissions ⇒ Object (readonly)
Returns the value of attribute permissions.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def @permissions end |
#platform ⇒ Object
Returns the value of attribute platform.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def platform @platform end |
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def storage @storage end |
#user_agent ⇒ Object
Returns the value of attribute user_agent.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def user_agent @user_agent end |
#vendor ⇒ Object
Returns the value of attribute vendor.
11 12 13 |
# File 'lib/dommy/navigator.rb', line 11 def vendor @vendor end |
#wake_lock ⇒ Object (readonly)
Returns the value of attribute wake_lock.
31 32 33 |
# File 'lib/dommy/navigator.rb', line 31 def wake_lock @wake_lock end |
Instance Method Details
#[](key) ⇒ Object
70 71 72 |
# File 'lib/dommy/navigator.rb', line 70 def [](key) __js_get__(key.to_s) end |
#[]=(k, v) ⇒ Object
74 75 76 |
# File 'lib/dommy/navigator.rb', line 74 def []=(k, v) __js_set__(k.to_s, v) end |
#__js_call__(method, args) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/dommy/navigator.rb', line 109 def __js_call__(method, args) case method when "share" share(args[0]) when "canShare" can_share(args[0]) when "vibrate" vibrate(args[0]) when "getBattery" get_battery end end |
#__js_get__(key) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dommy/navigator.rb', line 78 def __js_get__(key) case key when "userAgent" @user_agent when "language" @language when "languages" @languages when "platform" @platform when "vendor" @vendor when "onLine" @on_line when "cookieEnabled" @cookie_enabled when "clipboard" @clipboard when "permissions" @permissions when "geolocation" @geolocation when "wakeLock" @wake_lock when "locks" @locks when "storage" @storage end end |
#__js_set__(_key, _value) ⇒ Object
122 123 124 |
# File 'lib/dommy/navigator.rb', line 122 def __js_set__(_key, _value) nil end |
#__last_shared__ ⇒ Object
58 59 60 |
# File 'lib/dommy/navigator.rb', line 58 def __last_shared__ @last_shared end |
#__vibration_log__ ⇒ Object
54 55 56 |
# File 'lib/dommy/navigator.rb', line 54 def __vibration_log__ @vibration_log.dup end |
#can_share(_data = nil) ⇒ Object Also known as:
40 41 42 |
# File 'lib/dommy/navigator.rb', line 40 def can_share(_data = nil) true end |
#get_battery ⇒ Object Also known as: getBattery
Battery Status API stub. Returns a Promise resolving to a fixed ‘BatteryManager` snapshot.
64 65 66 |
# File 'lib/dommy/navigator.rb', line 64 def get_battery PromiseValue.resolve(@window, BatteryManager.new) end |
#share(data = nil) ⇒ Object
Web Share API. Returns a Promise; tests can inspect ‘last_shared` to verify what was offered.
35 36 37 38 |
# File 'lib/dommy/navigator.rb', line 35 def share(data = nil) @last_shared = data PromiseValue.resolve(@window, nil) end |
#vibrate(pattern) ⇒ Object
Vibration API. No-op in dommy, but the requested pattern is recorded so tests can assert “we asked to vibrate”.
48 49 50 51 52 |
# File 'lib/dommy/navigator.rb', line 48 def vibrate(pattern) list = pattern.is_a?(Array) ? pattern : [pattern] @vibration_log << list.map(&:to_i) true end |