Class: TagTreeScanner::TextNode

Inherits:
Object
  • Object
show all
Defined in:
lib/tagtreescanner.rb

Overview

A TextNode holds raw text inside a Tag. Generally, TextNodes are created automatically by the Tag#<< method.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = '') ⇒ TextNode

text

The text to start out with



678
679
680
681
# File 'lib/tagtreescanner.rb', line 678

def initialize( text='' )
  @text = text
  @info = {}
end

Instance Attribute Details

#infoObject

A hash which may be used to store ‘extra’ information



672
673
674
# File 'lib/tagtreescanner.rb', line 672

def info
  @info
end

#next_siblingObject

The Tag or TextNode that comes after this one (may be nil)



663
664
665
# File 'lib/tagtreescanner.rb', line 663

def next_sibling
  @next_sibling
end

#parent_tagObject

The Tag that is a parent of this TextNode (may be nil)



669
670
671
# File 'lib/tagtreescanner.rb', line 669

def parent_tag
  @parent_tag
end

#previous_siblingObject

The Tag or TextNode that comes before this one (may be nil)



666
667
668
# File 'lib/tagtreescanner.rb', line 666

def previous_sibling
  @previous_sibling
end

#textObject

The string contents of this text node



675
676
677
# File 'lib/tagtreescanner.rb', line 675

def text
  @text
end

Instance Method Details

#<<(additional_text) ⇒ Object

additional_text

The text to add

Appends the provided text to the end of the current text

Returns the new text value



688
689
690
# File 'lib/tagtreescanner.rb', line 688

def << ( additional_text )
  @text << additional_text
end

#dupObject

Returns a copy of this text node



693
694
695
# File 'lib/tagtreescanner.rb', line 693

def dup
  tag = self.class.new( @text.dup )
end

#to_hier(level = 0) ⇒ Object

:nodoc:



697
698
699
# File 'lib/tagtreescanner.rb', line 697

def to_hier( level=0 ) #:nodoc:
  "#{"\t"*level}#{@text.inspect}\n"
end

#to_sObject

:nodoc:



701
702
703
# File 'lib/tagtreescanner.rb', line 701

def to_s #:nodoc:
  @text
end

#to_xml(*args) ⇒ Object

Returns the contents of this node, modified to be made XML-safe by calling String#xmlsafe.



707
708
709
# File 'lib/tagtreescanner.rb', line 707

def to_xml( *args )
  @text.xmlsafe
end