Class: Coradoc::AsciiDoc::Model::DocumentAttributes
- Inherits:
-
Base
- Object
- Lutaml::Model::Serializable
- Base
- Coradoc::AsciiDoc::Model::DocumentAttributes
- Defined in:
- lib/coradoc/asciidoc/model/document_attributes.rb
Overview
Container for document-level attributes.
DocumentAttributes holds key-value pairs that define document metadata and configuration options. These are the ‘:key: value` declarations at the top of an AsciiDoc file.
Instance Attribute Summary collapse
-
#data ⇒ Array<Attribute>
readonly
Array of attribute key-value pairs.
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#block_level?, #inline?, #serialize_content, #simplify_block_content, #to_adoc, #to_h, visit, #visit
Instance Attribute Details
#data ⇒ Array<Attribute> (readonly)
Returns Array of attribute key-value pairs.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/coradoc/asciidoc/model/document_attributes.rb', line 23 class DocumentAttributes < Base attribute :data, Attribute, collection: true def to_hash return {} if data.nil? data.each_with_object({}) do |attribute, hash| hash[attribute.key.to_s] = attribute.value end end def get_attribute(name) return nil if data.nil? attribute = data.find { |attr| attr.key.to_s == name.to_s } attribute&.value end end |
Instance Method Details
#get_attribute(name) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/coradoc/asciidoc/model/document_attributes.rb', line 34 def get_attribute(name) return nil if data.nil? attribute = data.find { |attr| attr.key.to_s == name.to_s } attribute&.value end |
#to_hash ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/coradoc/asciidoc/model/document_attributes.rb', line 26 def to_hash return {} if data.nil? data.each_with_object({}) do |attribute, hash| hash[attribute.key.to_s] = attribute.value end end |