class Gammo::Node::Element

Represents the element token including start, end and self-closing token.

Public Instance Methods

inner_text() click to toggle source

TODO: The current innerText() implementation does not conform to WHATWG spec. html.spec.whatwg.org/multipage/dom.html#the-innertext-idl-attribute

# File lib/gammo/node.rb, line 68
def inner_text
  text = ''
  each_descendant { |node| text << node.data if node.instance_of?(Text) }
  text
end
to_s() click to toggle source
# File lib/gammo/node.rb, line 74
def to_s
  s = "<#{tag}"
  attrs = attributes_to_string
  s << ' ' unless attrs.empty?
  s << "#{attrs}>"
end

Private Instance Methods

attributes_to_string() click to toggle source
# File lib/gammo/node.rb, line 83
def attributes_to_string
  attributes.each_with_object([]) { |attr, attrs|
    attrs << "#{attr.key}=#{attr.value}"
  }.join(?\s)
end