Class: DocTemplate::Objects::TocMetadata
- Inherits:
-
Object
- Object
- DocTemplate::Objects::TocMetadata
- Defined in:
- lib/doc_template/objects/toc_metadata.rb
Defined Under Namespace
Classes: Heading
Class Method Summary collapse
Instance Method Summary collapse
- #append(toc) ⇒ Object
- #collect_children ⇒ Object
- #collect_material_ids ⇒ Object
- #ordered_material_ids ⇒ Object
- #prepend(toc) ⇒ Object
- #total_time_with(excludes) ⇒ Object
Class Method Details
.dump(data) ⇒ Object
53 54 55 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 53 def dump(data) data.as_json end |
.load(data) ⇒ Object
57 58 59 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 57 def load(data) new(data) end |
Instance Method Details
#append(toc) ⇒ Object
62 63 64 65 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 62 def append(toc) children.concat toc.children update_time end |
#collect_children ⇒ Object
67 68 69 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 67 def collect_children children + children.flat_map(&:children) end |
#collect_material_ids ⇒ Object
71 72 73 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 71 def collect_material_ids collect_children.flat_map(&:material_ids).compact.uniq end |
#ordered_material_ids ⇒ Object
75 76 77 78 79 80 81 82 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 75 def ordered_material_ids [].tap do |ids| children.each do |x| ids.concat x.material_ids ids.concat x.children.flat_map(&:material_ids) end end.compact end |
#prepend(toc) ⇒ Object
84 85 86 87 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 84 def prepend(toc) children.unshift(*toc.children) update_time end |
#total_time_with(excludes) ⇒ Object
89 90 91 92 93 94 95 96 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 89 def total_time_with(excludes) has_optionals = children.any? { |l1| l1.children.any?(&:optional) } if has_optionals || excludes.any? children.sum { |c| c.time_with(excludes) } else total_time end end |