Class: Motion::HTML::Element
- Inherits:
-
Object
- Object
- Motion::HTML::Element
- Defined in:
- lib/project/motion-html.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #attributes ⇒ Object
- #children ⇒ Object
-
#initialize(element) ⇒ Element
constructor
A new instance of Element.
- #inspect ⇒ Object
- #next_sibling ⇒ Object
- #parent ⇒ Object
- #tag ⇒ Object
- #text ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(element) ⇒ Element
Returns a new instance of Element.
25 26 27 |
# File 'lib/project/motion-html.rb', line 25 def initialize(element) @element = element end |
Instance Method Details
#[](key) ⇒ Object
41 42 43 |
# File 'lib/project/motion-html.rb', line 41 def [](key) attributes[key] end |
#attributes ⇒ Object
37 38 39 |
# File 'lib/project/motion-html.rb', line 37 def attributes @element.attributes end |
#children ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/project/motion-html.rb', line 50 def children elements = [] @element.childNodes.each do |node| elements << Element.new(node) if node.is_a? HTMLElement end elements end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/project/motion-html.rb', line 64 def inspect to_html end |
#next_sibling ⇒ Object
58 59 60 61 62 |
# File 'lib/project/motion-html.rb', line 58 def next_sibling el = @element.nextSibling el = el.nextSibling if el.is_a? HTMLText Element.new(el) if el.is_a? HTMLElement end |
#parent ⇒ Object
45 46 47 48 |
# File 'lib/project/motion-html.rb', line 45 def parent el = @element.parentNode Element.new(el) if el.is_a? HTMLElement end |
#tag ⇒ Object
29 30 31 |
# File 'lib/project/motion-html.rb', line 29 def tag @element.tagName end |
#text ⇒ Object
33 34 35 |
# File 'lib/project/motion-html.rb', line 33 def text @element.textContent end |
#to_html ⇒ Object
68 69 70 |
# File 'lib/project/motion-html.rb', line 68 def to_html @element.outerHTML end |