Class: DocTemplate::Objects::TocMetadata::Heading

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

Instance Method Summary collapse

Instance Method Details

#excluded?(excludes, ela: false) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
28
# File 'lib/doc_template/objects/toc_metadata.rb', line 21

def excluded?(excludes, ela: false)
  # Do not exclude parent if all children are optional and deselected
  return false if ela && children.all?(&:optional)
  return excludes.exclude?(anchor) if optional
  return true if excludes.include?(anchor)

  children.any? && children.all? { |c| c.excluded?(excludes) }
end

#time_with(excludes) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/doc_template/objects/toc_metadata.rb', line 30

def time_with(excludes)
  # Optional and nothing to exclude explicitly
  return excludes.include?(anchor) ? time : 0 if optional
  # General and excluded explicitly
  return 0 if excludes.include?(anchor)

  # do not recalculate time if
  # - there are no optional children
  # - no excludes passed
  # - there are no children at all
  if children.blank? || excludes.blank?
    time
  else
    children.sum { |c| c.time_with(excludes) }
  end
end