Class: HTMLTree::Data

Inherits:
Object
  • Object
show all
Includes:
TreeElement
Defined in:
lib/html/element.rb,
lib/html/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, #has_children?, #parent, #parent=, #path, #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.



307
308
309
# File 'lib/html/element.rb', line 307

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

Instance Method Details

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



44
45
46
# File 'lib/html/xpath.rb', line 44

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

#attributesObject

Return my (empty) attributes Hash.



294
# File 'lib/html/element.rb', line 294

def attributes; {}; end

#can_have_children?Boolean

Return false because I have no children.

Returns:

  • (Boolean)


285
# File 'lib/html/element.rb', line 285

def can_have_children?; false; end

#childrenObject

Return an empty collection because I have no children.



288
# File 'lib/html/element.rb', line 288

def children; []; end

#data?Boolean

Return true because I am a data Element.

Returns:

  • (Boolean)


282
# File 'lib/html/element.rb', line 282

def data?; true; end

#tagObject

Return my (empty) tag String.



291
# File 'lib/html/element.rb', line 291

def tag; ''; end

#to_sObject



296
297
298
# File 'lib/html/element.rb', line 296

def to_s
  @_content
end

#write(io) ⇒ Object

Print me on the given IO stream.



301
302
303
# File 'lib/html/element.rb', line 301

def write(io)
  io << self
end