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.



233
234
235
236
# File 'lib/lutaml/xml/data_model.rb', line 233

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

Instance Attribute Details

#contentObject

Returns the value of attribute content.



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

def content
  @content
end

#targetObject

Returns the value of attribute target.



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

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



250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/lutaml/xml/data_model.rb', line 250

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



238
239
240
# File 'lib/lutaml/xml/data_model.rb', line 238

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