Class: NSWTopo::Chrome::Node
- Inherits:
-
Object
- Object
- NSWTopo::Chrome::Node
- Defined in:
- lib/nswtopo/chrome.rb
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, value) ⇒ Object
-
#initialize(browser, selector) ⇒ Node
constructor
A new instance of Node.
- #value=(value) ⇒ Object
- #width ⇒ Object
Constructor Details
#initialize(browser, selector) ⇒ Node
Returns a new instance of Node.
199 200 201 |
# File 'lib/nswtopo/chrome.rb', line 199 def initialize(browser, selector) @browser, @node_id = browser, browser.query_selector_node_id(selector) end |
Instance Method Details
#[](name) ⇒ Object
203 204 205 206 207 |
# File 'lib/nswtopo/chrome.rb', line 203 def [](name) @browser.command("DOM.getAttributes", nodeId: @node_id).fetch("attributes").each_slice(2).to_h.fetch(name.to_s) rescue KeyError raise Error end |
#[]=(name, value) ⇒ Object
209 210 211 212 213 214 215 |
# File 'lib/nswtopo/chrome.rb', line 209 def []=(name, value) if value.nil? @browser.command "DOM.removeAttribute", nodeId: @node_id, name: name else @browser.command "DOM.setAttributeValue", nodeId: @node_id, name: name, value: value end end |
#value=(value) ⇒ Object
217 218 219 |
# File 'lib/nswtopo/chrome.rb', line 217 def value=(value) @browser.command "DOM.setNodeValue", nodeId: @node_id + 1, value: value end |
#width ⇒ Object
221 222 223 224 225 |
# File 'lib/nswtopo/chrome.rb', line 221 def width @browser.command("DOM.getBoxModel", nodeId: @node_id).fetch("model").fetch("content").each_slice(2).map(&:first).minmax.reverse.inject(&:-) rescue KeyError raise Error end |