Class: OperaWatir::Preferences
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/operawatir/preferences.rb
Overview
OperaWatir::Preferences enables you to access the browser preferences in the Opera web browser.
Defined Under Namespace
Classes: Section
Instance Attribute Summary collapse
-
#browser ⇒ Object
Returns the value of attribute browser.
-
#driver ⇒ Object
Returns the value of attribute driver.
Instance Method Summary collapse
-
#exists? ⇒ Boolean
(also: #exist?)
Checks if any preferences exists in your Opera build.
-
#initialize(browser) ⇒ Preferences
constructor
The OperaWatir::Preferences object is created automatically when you create an OperaWatir::Browser object, and is available as Browser#prefrences.
-
#method_missing(method) ⇒ Object
When calling Preferences#any_method_name, the ‘any_method_name` will be caught by this method.
-
#to_a ⇒ Array
Returns a list of all preferences in array form.
-
#to_s ⇒ String
Retrieves a human-readable list of Opera preferences available.
Constructor Details
#initialize(browser) ⇒ Preferences
The OperaWatir::Preferences object is created automatically when you create an OperaWatir::Browser object, and is available as Browser#prefrences.
121 122 123 124 125 126 127 128 129 |
# File 'lib/operawatir/preferences.rb', line 121 def initialize(browser) self.browser, self.driver = browser, browser.driver raw_prefs = driver.listAllPrefs.to_a @_prefs = {} @_prefs = raw_prefs.map { |s| Section.new(self, s) }.sort_by { |s| s.key } @old_prefs = _prefs end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method) ⇒ Object
When calling Preferences#any_method_name, the ‘any_method_name` will be caught by this method.
This is the standard way of looking up sections. ‘any_method_name` should be replaced by a methodized version of the section as it appears in the Opera preferences list which you can find at `opera:config`.
157 158 159 160 161 162 163 |
# File 'lib/operawatir/preferences.rb', line 157 def method_missing(method) method = method.to_s if _prefs.any? { |s| s.method == method } _prefs.find { |s| s.method == method } end end |
Instance Attribute Details
#browser ⇒ Object
Returns the value of attribute browser.
107 108 109 |
# File 'lib/operawatir/preferences.rb', line 107 def browser @browser end |
#driver ⇒ Object
Returns the value of attribute driver.
107 108 109 |
# File 'lib/operawatir/preferences.rb', line 107 def driver @driver end |
Instance Method Details
#exists? ⇒ Boolean Also known as: exist?
Checks if any preferences exists in your Opera build. If true, there are preferences available, false otherwise.
214 215 216 |
# File 'lib/operawatir/preferences.rb', line 214 def exists? !_prefs.empty? end |
#to_a ⇒ Array
Returns a list of all preferences in array form. This can be used for external parsing. If you wish to manipulate or iterate through the list of preferences, consider using the built-in Ruby iterator #each (with friends).
203 204 205 |
# File 'lib/operawatir/preferences.rb', line 203 def to_a _prefs.dup end |
#to_s ⇒ String
Retrieves a human-readable list of Opera preferences available. This is used for convenience and should never be parsed. Consider using the built-in Ruby iterator #each (with friends) or Preferences#to_a for that.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/operawatir/preferences.rb', line 174 def to_s text = '' _prefs.each do |s| text << "#{s.method}\n" s.each do |k| text << " #{k.method}\n" text << " type: #{k.type.inspect}\n" text << " value: #{k.value.inspect}\n" text << " default: #{k.default.inspect}\n" text << " enabled: #{k.enabled?.inspect}\n" end text << "\n" end text end |