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



530
531
532
533
# File 'lib/tagtreescanner.rb', line 530

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

Instance Attribute Details

#infoObject

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



524
525
526
# File 'lib/tagtreescanner.rb', line 524

def info
  @info
end

#next_siblingObject

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



515
516
517
# File 'lib/tagtreescanner.rb', line 515

def next_sibling
  @next_sibling
end

#parent_tagObject

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



521
522
523
# File 'lib/tagtreescanner.rb', line 521

def parent_tag
  @parent_tag
end

#previous_siblingObject

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



518
519
520
# File 'lib/tagtreescanner.rb', line 518

def previous_sibling
  @previous_sibling
end

#textObject

The string contents of this text node



527
528
529
# File 'lib/tagtreescanner.rb', line 527

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



540
541
542
# File 'lib/tagtreescanner.rb', line 540

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

#dupObject

Returns a copy of this text node



545
546
547
# File 'lib/tagtreescanner.rb', line 545

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

#to_hier(level = 0) ⇒ Object

:nodoc:



549
550
551
# File 'lib/tagtreescanner.rb', line 549

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

#to_sObject

:nodoc:



553
554
555
# File 'lib/tagtreescanner.rb', line 553

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.



559
560
561
# File 'lib/tagtreescanner.rb', line 559

def to_xml( *args )
  @text.xmlsafe
end