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
55 56 57 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 55 def dump(data) data.as_json end |
.load(data) ⇒ Object
59 60 61 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 59 def load(data) new(data) end |
Instance Method Details
#append(toc) ⇒ Object
64 65 66 67 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 64 def append(toc) children.concat toc.children update_time end |
#collect_children ⇒ Object
69 70 71 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 69 def collect_children children + children.flat_map(&:children) end |
#collect_material_ids ⇒ Object
73 74 75 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 73 def collect_material_ids collect_children.flat_map(&:material_ids).compact.uniq end |
#ordered_material_ids ⇒ Object
77 78 79 80 81 82 83 84 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 77 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
86 87 88 89 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 86 def prepend(toc) children.unshift(*toc.children) update_time end |
#total_time_with(excludes) ⇒ Object
91 92 93 94 95 96 97 98 |
# File 'lib/doc_template/objects/toc_metadata.rb', line 91 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 |