class Wrapture::Comment

A comment that can be inserted in generated source code.

Comments are primarily used to insert documentation about generated code for documentation generation tools such as Doxygen.

Attributes

text[R]

The raw text of the comment.

Public Class Methods

new(comment = '') click to toggle source

Creates a comment from a string. If the provided string is nil, then an empty string is used.

# File lib/wrapture/comment.rb, line 37
def initialize(comment = '')
  @text = comment.nil? ? '' : comment
end
validate_doc(doc) click to toggle source

Validates a doc string.

# File lib/wrapture/comment.rb, line 28
def self.validate_doc(doc)
  raise InvalidDoc, 'a doc must be a string' unless doc.is_a?(String)
end

Public Instance Methods

empty?() click to toggle source

True if this comment is empty, false otherwise.

# File lib/wrapture/comment.rb, line 42
def empty?
  @text.empty?
end
format(line_prefix: '// ', first_line: nil, last_line: nil, max_line_length: 80) { |first_line| ... } click to toggle source

Yields each line of the comment formatted as specified.

# File lib/wrapture/comment.rb, line 47
def format(line_prefix: '// ', first_line: nil, last_line: nil,
           max_line_length: 80)
  return if @text.empty?

  yield first_line if first_line

  paragraphs(max_line_length - line_prefix.length) do |line|
    yield "#{line_prefix}#{line}".rstrip
  end

  yield last_line if last_line
end
format_as_doxygen(max_line_length: 80) { |line| ... } click to toggle source

Yields each line of the comment formatted using Doxygen style.

# File lib/wrapture/comment.rb, line 61
def format_as_doxygen(max_line_length: 80)
  format(line_prefix: ' * ', first_line: '/**',
         last_line: ' */', max_line_length: max_line_length) do |line|
    yield line
  end
end