Class: Wrapture::Comment
- Inherits:
-
Object
- Object
- Wrapture::Comment
- Defined in:
- lib/wrapture/comment.rb
Overview
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.
Instance Attribute Summary collapse
-
#text ⇒ Object
readonly
The raw text of the comment.
Class Method Summary collapse
-
.validate_doc(doc) ⇒ Object
Validates a doc string.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
True if this comment is empty, false otherwise.
-
#format(line_prefix: '// ', first_line: nil, last_line: nil, max_line_length: 80) {|first_line| ... } ⇒ Object
Yields each line of the comment formatted as specified.
-
#format_as_doxygen(max_line_length: 80, &block) ⇒ Object
Calls the given block for each line of the comment formatted using Doxygen style.
-
#initialize(comment = '') ⇒ Comment
constructor
Creates a comment from a string.
Constructor Details
#initialize(comment = '') ⇒ Comment
Creates a comment from a string. If the provided string is nil, then an empty string is used.
37 38 39 |
# File 'lib/wrapture/comment.rb', line 37 def initialize(comment = '') @text = comment.nil? ? '' : comment end |
Instance Attribute Details
#text ⇒ Object (readonly)
The raw text of the comment.
33 34 35 |
# File 'lib/wrapture/comment.rb', line 33 def text @text end |
Class Method Details
.validate_doc(doc) ⇒ Object
Validates a doc string.
28 29 30 |
# 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 |
Instance Method Details
#empty? ⇒ Boolean
True if this comment is empty, false otherwise.
42 43 44 |
# 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| ... } ⇒ Object
Yields each line of the comment formatted as specified.
47 48 49 50 51 52 53 54 55 56 57 58 |
# 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, &block) ⇒ Object
Calls the given block for each line of the comment formatted using Doxygen style.
62 63 64 65 66 67 |
# File 'lib/wrapture/comment.rb', line 62 def format_as_doxygen(max_line_length: 80, &block) format(line_prefix: ' * ', first_line: '/**', last_line: ' */', max_line_length: max_line_length) do |line| block.call(line) end end |