Class: Philiprehberger::XmlBuilder::ProcessingInstruction
- Inherits:
-
Object
- Object
- Philiprehberger::XmlBuilder::ProcessingInstruction
- Defined in:
- lib/philiprehberger/xml_builder/processing_instruction.rb
Overview
Represents an XML processing instruction (PI).
Renders as <?target key=“value” key2=“value2”?>, with attribute values escaped via Escaper.
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Instance Method Summary collapse
-
#initialize(target, attributes = {}) ⇒ ProcessingInstruction
constructor
A new instance of ProcessingInstruction.
-
#render(indent: nil, level: 0) ⇒ Object
Alias for to_xml to match Node#render semantics.
-
#to_xml(indent: nil, level: 0, pretty: false) ⇒ String
Render this processing instruction as an XML string.
Constructor Details
#initialize(target, attributes = {}) ⇒ ProcessingInstruction
Returns a new instance of ProcessingInstruction.
14 15 16 17 |
# File 'lib/philiprehberger/xml_builder/processing_instruction.rb', line 14 def initialize(target, attributes = {}) @target = target.to_s @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
10 11 12 |
# File 'lib/philiprehberger/xml_builder/processing_instruction.rb', line 10 def attributes @attributes end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
10 11 12 |
# File 'lib/philiprehberger/xml_builder/processing_instruction.rb', line 10 def target @target end |
Instance Method Details
#render(indent: nil, level: 0) ⇒ Object
Alias for to_xml to match Node#render semantics.
32 33 34 |
# File 'lib/philiprehberger/xml_builder/processing_instruction.rb', line 32 def render(indent: nil, level: 0) to_xml(indent: indent, level: level, pretty: !indent.nil?) end |
#to_xml(indent: nil, level: 0, pretty: false) ⇒ String
Render this processing instruction as an XML string.
25 26 27 28 29 |
# File 'lib/philiprehberger/xml_builder/processing_instruction.rb', line 25 def to_xml(indent: nil, level: 0, pretty: false) prefix = indent && pretty ? ' ' * (indent * level) : '' newline = indent && pretty ? "\n" : '' "#{prefix}<?#{@target}#{render_attributes}?>#{newline}" end |