123456789_123456789_123456789_123456789_123456789_

Class: REXML::Instruction

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, Child
Instance Chain:
self, Child, Node
Inherits: REXML::Child
Defined in: lib/rexml/instruction.rb

Overview

Represents an XML Instruction; IE, <? … ?> TODO: Add parent arg (3rd arg) to constructor

Constant Summary

Class Method Summary

Child - Inherited

.new

Constructor.

Instance Attribute Summary

  • #content rw

    target is the “name” of the Instruction; IE, the “tag” in <?tag …?> content is everything else.

  • #target rw

    target is the “name” of the Instruction; IE, the “tag” in <?tag …?> content is everything else.

Child - Inherited

#next_sibling
#next_sibling=

Sets the next sibling of this child.

#parent

The Parent of this object.

#parent=

Sets the parent of this child to the supplied argument.

#previous_sibling
#previous_sibling=

Sets the previous sibling of this child.

Node - Included

Instance Method Summary

Child - Inherited

#bytes

This doesn't yet handle encodings.

#document
Returns

the document this child belongs to, or nil if this child belongs to no document.

#remove

Removes this child from the parent.

#replace_with

Replaces this object with another object.

Node - Included

#each_recursive

Visit all subnodes of self recursively.

#find_first_recursive

Find (and return) first subnode (recursively) for which the block evaluates to true.

#indent,
#index_in_parent

Returns the position that self holds in its parent's array, indexed from 1.

#next_sibling_node, #previous_sibling_node,
#to_s
indent

Constructor Details

.new(target, content = nil) ⇒ Instruction

Constructs a new Instruction the target of this instruction is set to this. If an Instruction, then the Instruction is shallowly cloned (target and content are copied). If a Source, then the source is scanned and parsed for an Instruction declaration. be a Parent if the target argument is a Source. Otherwise, this String is set as the content of this instruction.

Parameters:

  • target

    can be one of a number of things. If String, then

  • content (defaults to: nil)

    Must be either a String, or a Parent. Can only

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 24

def initialize(target, content=nil)
  if target.kind_of? String
    super()
    @target = target
    @content = content
  elsif target.kind_of? Instruction
    super(content)
    @target = target.target
    @content = target.content
  end
  @content.strip! if @content
end

Instance Attribute Details

#content (rw)

target is the “name” of the Instruction; IE, the “tag” in <?tag …?> content is everything else.

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 13

attr_accessor :target, :content

#target (rw)

target is the “name” of the Instruction; IE, the “tag” in <?tag …?> content is everything else.

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 13

attr_accessor :target, :content

Instance Method Details

#==(other) ⇒ Object

of the other matches the target and content of this object.

Returns:

  • true if other is an Instruction, and the content and target

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 56

def ==( other )
  other.kind_of? Instruction and
  other.target == @target and
  other.content == @content
end

#clone

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 37

def clone
  Instruction.new self
end

#inspect

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 66

def inspect
  "<?p-i #{target} ...?>"
end

#node_type

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 62

def node_type
  :processing_instruction
end

#write(writer, indent = -1,, transitive = false, ie_hack = false)

DEPRECATED

See the rexml/formatters package

[ GitHub ]

  
# File 'lib/rexml/instruction.rb', line 44

def write writer, indent=-1, transitive=false, ie_hack=false
  Kernel.warn( "#{self.class.name}.write is deprecated" )
  indent(writer, indent)
  writer << START.sub(/\\/u, '')
  writer << @target
  writer << ' '
  writer << @content
  writer << STOP.sub(/\\/u, '')
end