Class: Coradoc::CoreModel::Metadata
- Defined in:
- lib/coradoc/core_model/metadata.rb
Overview
Represents metadata associated with a document element
Stores arbitrary key-value pairs for tracking source location, processing information, and other contextual data.
Instance Attribute Summary
Attributes inherited from Base
#element_attributes, #id, #metadata_entries, #title
Instance Method Summary collapse
-
#[](key) ⇒ String?
Get a metadata value by key.
-
#[]=(key, value) ⇒ Object
Set a metadata value.
-
#key?(key) ⇒ Boolean
Check if a key exists.
-
#keys ⇒ Array<String>
Get all keys.
-
#to_h ⇒ Hash
Convert to hash representation.
Methods inherited from Base
#accept, #attr, #metadata, #semantically_equivalent?, #set_attr, #set_metadata
Instance Method Details
#[](key) ⇒ String?
Get a metadata value by key
26 27 28 29 30 |
# File 'lib/coradoc/core_model/metadata.rb', line 26 def [](key) return nil if entries.nil? find_entry(key)&.value end |
#[]=(key, value) ⇒ Object
Set a metadata value
35 36 37 38 39 40 41 42 43 |
# File 'lib/coradoc/core_model/metadata.rb', line 35 def []=(key, value) self.entries ||= [] existing = find_entry(key) if existing existing.value = value else entries << MetadataEntry.new(key: key, value: value) end end |
#key?(key) ⇒ Boolean
Check if a key exists
48 49 50 51 52 |
# File 'lib/coradoc/core_model/metadata.rb', line 48 def key?(key) return false if entries.nil? !find_entry(key).nil? end |
#keys ⇒ Array<String>
Get all keys
56 57 58 59 60 |
# File 'lib/coradoc/core_model/metadata.rb', line 56 def keys return [] if entries.nil? entries.map(&:key) end |
#to_h ⇒ Hash
Convert to hash representation
64 65 66 67 68 |
# File 'lib/coradoc/core_model/metadata.rb', line 64 def to_h return {} if entries.nil? entries.each_with_object({}) { |entry, hash| hash[entry.key] = entry.value } end |