Class: HTMLTree::Data

Inherits:
Object show all
Includes:
TreeElement
Defined in:
lib/web/htmltools/element.rb,
lib/web/htmltools/xpath.rb

Overview

This is a TreeElement that represents leaf data nodes (CDATA, scripts, comments, processing directives). It forwards unknown messages to the content element, so it otherwise behaves like a String.

Direct Known Subclasses

Comment, Special

Instance Method Summary collapse

Methods included from TreeElement

#add_child, #content, #dump, #each, #get_elements, #has_children?, #parent, #parent=, #remove_child, #rexml_match, #root

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

Forward all other methods to my content, so I can otherwise behave like a String.



280
281
282
# File 'lib/web/htmltools/element.rb', line 280

def method_missing(sym, *args)
  @_content.method(sym).call(*args)
end

Instance Method Details

#as_rexml_document(rparent = nil, context = {}) ⇒ Object



43
44
45
# File 'lib/web/htmltools/xpath.rb', line 43

def as_rexml_document(rparent = nil, context = {})
  rparent.add_text(@_content)
end

#attributesObject

Return my (empty) attributes Hash.



267
# File 'lib/web/htmltools/element.rb', line 267

def attributes; {}; end

#can_have_children?Boolean

Return false because I have no children.

Returns:

  • (Boolean)


258
# File 'lib/web/htmltools/element.rb', line 258

def can_have_children?; false; end

#childrenObject

Return an empty collection because I have no children.



261
# File 'lib/web/htmltools/element.rb', line 261

def children; []; end

#data?Boolean

Return true because I am a data Element.

Returns:

  • (Boolean)


255
# File 'lib/web/htmltools/element.rb', line 255

def data?; true; end

#tagObject

Return my (empty) tag String.



264
# File 'lib/web/htmltools/element.rb', line 264

def tag; ''; end

#to_sObject



269
270
271
# File 'lib/web/htmltools/element.rb', line 269

def to_s
  @_content
end

#write(io) ⇒ Object

Print me on the given IO stream.



274
275
276
# File 'lib/web/htmltools/element.rb', line 274

def write(io)
  io << self
end