class RDocRuboCop::Lang::C::Comment::Normal

This class manages comments of the following form:

/*
 * Document-class: Foo
 *
 *   code1
 *   code2
 */

Public Instance Methods

corrected_text() click to toggle source
# File lib/rdoc_rubocop/lang/c/comment/normal.rb, line 20
def corrected_text
  body = rdoc.apply

  first_line = body.slice!(/\A.*\R/)
  body.gsub!(/^/, indent)

  text = "/*#{@indent_after_asterisk}#{first_line}#{body}".gsub(/ *$/, "")
  "#{text}#{@end_str}"
end

Private Instance Methods

indent() click to toggle source
# File lib/rdoc_rubocop/lang/c/comment/normal.rb, line 55
def indent
  @indent_before_asterisk + @indent_after_asterisk
end
parse() click to toggle source
# File lib/rdoc_rubocop/lang/c/comment/normal.rb, line 32
def parse
  body = @comment_text.expand_tab

  #
  # /*          <- first_line
  #  * comment1
  #  *
  #  * comment2
  #  */         <- @end_str
  #
  first_line = body.slice!(/\A.*\R/)
  @end_str = body.slice!(%r(^.*\*/\z))

  tmp_indent = @end_str[/^ */]
  body = tmp_indent + "*" + first_line.sub(%r(/\*), "") + body

  @indent_before_asterisk = body.scan(/^ *\*/).min || ""
  @indent_after_asterisk = body.gsub(/^ *\*/, "").indent || ""
  indent = @indent_before_asterisk + @indent_after_asterisk

  @body = body.gsub(/^.{0,#{indent.length}}/, "")
end