PHP 8.2.31
Preview: document.rb Size: 3.15 KB
/proc/thread-self/root/opt/alt/ruby31/share/gems/gems/rdoc-6.4.1.1/lib/rdoc/markup/document.rb

# frozen_string_literal: true
##
# A Document containing lists, headings, paragraphs, etc.

class RDoc::Markup::Document

  include Enumerable

  ##
  # The file this document was created from.  See also
  # RDoc::ClassModule#add_comment

  attr_reader :file

  ##
  # If a heading is below the given level it will be omitted from the
  # table_of_contents

  attr_accessor :omit_headings_below

  ##
  # The parts of the Document

  attr_reader :parts

  ##
  # Creates a new Document with +parts+

  def initialize *parts
    @parts = []
    @parts.concat parts

    @file = nil
    @omit_headings_from_table_of_contents_below = nil
  end

  ##
  # Appends +part+ to the document

  def << part
    case part
    when RDoc::Markup::Document then
      unless part.empty? then
        parts.concat part.parts
        parts << RDoc::Markup::BlankLine.new
      end
    when String then
      raise ArgumentError,
            "expected RDoc::Markup::Document and friends, got String" unless
        part.empty?
    else
      parts << part
    end
  end

  def == other # :nodoc:
    self.class == other.class and
      @file == other.file and
      @parts == other.parts
  end

  ##
  # Runs this document and all its #items through +visitor+

  def accept visitor
    visitor.start_accepting

    visitor.accept_document self

    visitor.end_accepting
  end

  ##
  # Concatenates the given +parts+ onto the document

  def concat parts
    self.parts.concat parts
  end

  ##
  # Enumerator for the parts of this document

  def each &block
    @parts.each(&block)
  end

  ##
  # Does this document have no parts?

  def empty?
    @parts.empty? or (@parts.length == 1 and merged? and @parts.first.empty?)
  end

  ##
  # The file this Document was created from.

  def file= location
    @file = case location
            when RDoc::TopLevel then
              location.relative_name
            else
              location
            end
  end

  ##
  # When this is a collection of documents (#file is not set and this document
  # contains only other documents as its direct children) #merge replaces
  # documents in this class with documents from +other+ when the file matches
  # and adds documents from +other+ when the files do not.
  #
  # The information in +other+ is preferred over the receiver

  def merge other
    if empty? then
      @parts = other.parts
      return self
    end

    other.parts.each do |other_part|
      self.parts.delete_if do |self_part|
        self_part.file and self_part.file == other_part.file
      end

      self.parts << other_part
    end

    self
  end

  ##
  # Does this Document contain other Documents?

  def merged?
    RDoc::Markup::Document === @parts.first
  end

  def pretty_print q # :nodoc:
    start = @file ? "[doc (#{@file}): " : '[doc: '

    q.group 2, start, ']' do
      q.seplist @parts do |part|
        q.pp part
      end
    end
  end

  ##
  # Appends +parts+ to the document

  def push *parts
    self.parts.concat parts
  end

  ##
  # Returns an Array of headings in the document.
  #
  # Require 'rdoc/markup/formatter' before calling this method.

  def table_of_contents
    accept RDoc::Markup::ToTableOfContents.to_toc
  end

end

Directory Contents

Dirs: 0 × Files: 34

Name Size Perms Modified Actions
1.25 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
10.10 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
424 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
672 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
391 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
252 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
3.15 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
5.45 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
446 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.48 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
829 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
906 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.82 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.71 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
493 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
14.14 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
8.42 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1000 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
718 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
315 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
996 B lrw-r--r-- 2025-04-28 17:36:07
Edit Download
2.05 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.64 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
9.68 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
4.87 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
5.46 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.14 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.83 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
3.61 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
6.74 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.72 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.14 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
2.28 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download
1.28 KB lrw-r--r-- 2025-04-28 17:36:07
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).