Class: Lutaml::Xml::DataModel::XmlProcessingInstruction

Inherits:
Object
  • Object
show all
Defined in:
lib/lutaml/xml/data_model.rb

Overview

Represents an XML processing instruction.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, content) ⇒ XmlProcessingInstruction

Returns a new instance of XmlProcessingInstruction.



225
226
227
228
# File 'lib/lutaml/xml/data_model.rb', line 225

def initialize(target, content)
  @target = target
  @content = content
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



223
224
225
# File 'lib/lutaml/xml/data_model.rb', line 223

def content
  @content
end

#targetObject

Returns the value of attribute target.



223
224
225
# File 'lib/lutaml/xml/data_model.rb', line 223

def target
  @target
end

Class Method Details

.parse_pseudo_attributes(content) ⇒ Hash

Parse pseudo-attributes from PI content string.

Handles both single and multiple pseudo-attributes:

'strict="yes"' → {"strict"=>"yes"}
'toc="yes" oxy-markup="no"' → {"toc"=>"yes", "oxy-markup"=>"no"}

Parameters:

  • content (String)

    PI content with key=“value” pairs

Returns:

  • (Hash)

    Parsed key-value pairs



242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/lutaml/xml/data_model.rb', line 242

def self.parse_pseudo_attributes(content)
  return {} unless content.is_a?(String) && !content.strip.empty?

  chunks = content.split(/=['"]([^'"]*)['"]/)
  result = {}
  chunks.each_slice(2) do |key, value|
    next unless key && value

    result[key.strip] = value
  end
  result
end

Instance Method Details

#to_sObject



230
231
232
# File 'lib/lutaml/xml/data_model.rb', line 230

def to_s
  "<?#{target} #{content}?>"
end