Class: Coradoc::CoreModel::ListItem
- Includes:
- ChildrenContent
- Defined in:
- lib/coradoc/core_model/list_item.rb,
lib/coradoc/core_model/list_block.rb,
lib/coradoc/core_model/list_block.rb
Overview
Re-open ListItem to properly type nested_list now that ListBlock is defined
Instance Attribute Summary collapse
-
#children ⇒ Array
Array of attached blocks/elements (mixed content, via ChildrenContent).
-
#content ⇒ String?
Text content of the list item.
-
#marker ⇒ String?
The marker character(s) for this item (e.g., ‘*’, ‘**’, ‘.’, ‘..’, ‘-’).
-
#nested_list ⇒ ListBlock?
Note: Typed as string initially, retyped after ListBlock defined.
Attributes inherited from Base
#element_attributes, #id, #metadata_entries, #title
Class Method Summary collapse
-
.from_h(hash) ⇒ ListItem
Create from hash.
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ ListItem
constructor
Initialize with optional nested structure support.
-
#nested ⇒ Object
Delegate nested to nested_list (lutaml attribute added by list_block.rb).
-
#nested=(value) ⇒ Object
Set nested list.
-
#semantically_equivalent?(other) ⇒ Boolean
Override semantic equivalence to handle nested structures properly.
-
#to_h ⇒ Hash
Convert to hash representation.
Methods included from ChildrenContent
#flat_text, included, #renderable_content, #to_hash
Methods inherited from Base
#accept, #attr, #metadata, #set_attr, #set_metadata
Constructor Details
#initialize(args = {}) ⇒ ListItem
Initialize with optional nested structure support
40 41 42 43 44 |
# File 'lib/coradoc/core_model/list_item.rb', line 40 def initialize(args = {}) # Support :nested as alias for :nested_list args[:nested_list] = args.delete(:nested) if args.key?(:nested) super end |
Instance Attribute Details
#children ⇒ Array
Returns array of attached blocks/elements (mixed content, via ChildrenContent).
|
|
# File 'lib/coradoc/core_model/list_item.rb', line 35
|
#content ⇒ String?
Returns text content of the list item.
33 |
# File 'lib/coradoc/core_model/list_item.rb', line 33 attribute :content, :string |
#marker ⇒ String?
Returns the marker character(s) for this item (e.g., ‘*’, ‘**’, ‘.’, ‘..’, ‘-’).
29 |
# File 'lib/coradoc/core_model/list_item.rb', line 29 attribute :marker, :string |
#nested_list ⇒ ListBlock?
Note: Typed as string initially, retyped after ListBlock defined
40 |
# File 'lib/coradoc/core_model/list_block.rb', line 40 attribute :nested_list, :string |
Class Method Details
.from_h(hash) ⇒ ListItem
Create from hash
73 74 75 76 77 78 79 80 |
# File 'lib/coradoc/core_model/list_item.rb', line 73 def self.from_h(hash) new( marker: hash[:marker], content: hash[:content], nested: hash[:nested_list], children: hash[:children] || [] ) end |
Instance Method Details
#nested ⇒ Object
Delegate nested to nested_list (lutaml attribute added by list_block.rb)
47 48 49 |
# File 'lib/coradoc/core_model/list_item.rb', line 47 def nested nested_list if respond_to?(:nested_list) end |
#nested=(value) ⇒ Object
Set nested list
53 54 55 |
# File 'lib/coradoc/core_model/list_item.rb', line 53 def nested=(value) self.nested_list = value if respond_to?(:nested_list=) end |
#semantically_equivalent?(other) ⇒ Boolean
Override semantic equivalence to handle nested structures properly
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/coradoc/core_model/list_item.rb', line 83 def semantically_equivalent?(other) return false unless other.is_a?(self.class) return false unless content == other.content # Compare nested lists if present if nested || other.nested return false if nested.nil? != other.nested.nil? return false if nested && !lists_equivalent?(nested, other.nested) end # Compare children if present if children || other.children return false if children.nil? != other.children.nil? return false if children && !arrays_equivalent?(children, other.children) end true end |
#to_h ⇒ Hash
Convert to hash representation
60 61 62 63 64 65 66 67 |
# File 'lib/coradoc/core_model/list_item.rb', line 60 def to_h { marker: marker, content: content, nested_list: nested&.to_h, children: children&.map { |child| child.respond_to?(:to_h) ? child.to_h : child } }.compact end |