Class: Motion::HTML::Element

Inherits:
Object
  • Object
show all
Defined in:
lib/project/motion-html.rb

Instance Method Summary collapse

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

#attributesObject



37
38
39
# File 'lib/project/motion-html.rb', line 37

def attributes
  @element.attributes
end

#childrenObject



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

#inspectObject



64
65
66
# File 'lib/project/motion-html.rb', line 64

def inspect
  to_html
end

#next_siblingObject



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

#parentObject



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

#tagObject



29
30
31
# File 'lib/project/motion-html.rb', line 29

def tag
  @element.tagName
end

#textObject



33
34
35
# File 'lib/project/motion-html.rb', line 33

def text
  @element.textContent
end

#to_htmlObject



68
69
70
# File 'lib/project/motion-html.rb', line 68

def to_html
  @element.outerHTML
end