class RBS::Annotate::Formatter

Attributes

buffer[R]

Public Class Methods

each_part(doc) { |doc| ... } click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 58
def self.each_part(doc, &block)
  if block
    if doc.file
      yield doc
    else
      doc.each do |d|
        each_part(d, &block)
      end
    end
  else
    enum_for :each_part, doc
  end
end
new() click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 6
def initialize()
  @buffer = ""
  @pending_separator = nil
end
translate(doc) click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 72
def self.translate(doc)
  if doc.file
    formatter = RDoc::Markup::ToMarkdown.new
    doc.accept(formatter).strip.lines.map(&:rstrip).join("\n")
  end
end

Public Instance Methods

<<(s) click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 11
def <<(s)
  if s
    if s.is_a?(RDoc::Markup::Document)
      s = self.class.translate(s) or raise
    end

    s.rstrip!

    unless s.empty?
      if ss = @pending_separator
        buffer << ss
        buffer << "\n"
        @pending_separator = nil
      end

      buffer << s
      buffer << "\n"
    end
  end

  self
end
empty?() click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 42
def empty?
  buffer.empty?
end
format(newline_at_end:) click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 46
def format(newline_at_end:)
  unless buffer.empty?
    if newline_at_end
      buffer.strip + "\n\n"
    else
      buffer.strip + "\n"
    end
  else
    buffer
  end
end
margin(separator: "") click to toggle source
# File rbs-2.1.0/lib/rbs/annotate/formatter.rb, line 34
def margin(separator: "")
  unless buffer.empty?
    @pending_separator = separator
  end

  self
end