class RuboCop::Cop::Style::MethodDocRange

method doc range checks parts of the comment for correctness

Constants

DOC_PARM_REGEXP
PARM_END
PARM_START

Attributes

end[RW]
start[RW]
type[RW]

Public Class Methods

new(comments, type) click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 301
def initialize(comments, type)
  @comments = comments
  @type = type
end

Public Instance Methods

before?(method_doc_range) click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 306
def before?(method_doc_range)
  return true if missing? || method_doc_range.missing?

  @start < method_doc_range.start
end
empty_comm?(comment) click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 312
def empty_comm?(comment)
  txt = comment.text
  txt.size <= 2
end
end_comment() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 317
def end_comment
  @comments[@end]
end
ends_with_empty_comment?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 321
def ends_with_empty_comment?
  missing? || empty_comm?(end_comment)
end
first_comment?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 325
def first_comment?
  @start == 0
end
first_comment_equal?(text) click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 333
def first_comment_equal?(text)
  !missing? && start_comment.text == text
end
first_empty_comment?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 329
def first_empty_comment?
  missing? || empty_comm?(@comments[@start + 1])
end
missing?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 337
def missing?
  @start.nil?
end
parm_names() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 341
def parm_names
  names = []
  range_body.each do |parm_line|
    # puts "parm_line.text=#{parm_line}"
    # puts "match=#{DOC_PARM_REGEXP.match(parm_line.text).to_s}"
    DOC_PARM_REGEXP.match(parm_line.text) do |m|
      parm_name = m.to_s[PARM_START.size...m.to_s.index(PARM_END)]
      names.push([parm_line, parm_name])
      # puts "parm_name=#{parm_name}"
    end
  end
  # puts "names=#{names}"
  names
end
range_body() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 356
def range_body
  @comments[@start + (first_empty_comment? ? 2 : 1)...@end + (ends_with_empty_comment? ? 0 : 1)]
end
returns?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 360
def returns?
  @type == 'Return'
end
start_comment() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 364
def start_comment
  @comments[@start]
end
starts_with_empty_comment?() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 368
def starts_with_empty_comment?
  empty_comm?(@comments[@start])
end
to_s() click to toggle source
# File lib/rubocop/cop/style/public_method_documentation.rb, line 372
def to_s
  [missing? ? nil : start_comment, @start, @end]
end