Class: DocTemplate::Objects::TocMetadata

Inherits:
Object
  • Object
show all
Defined in:
lib/doc_template/objects/toc_metadata.rb

Defined Under Namespace

Classes: Heading

Class Method Summary collapse

Instance Method Summary collapse

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_childrenObject



67
68
69
# File 'lib/doc_template/objects/toc_metadata.rb', line 67

def collect_children
  children + children.flat_map(&:children)
end

#collect_material_idsObject



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_idsObject



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