Class: RDocRuboCop::Lang::C::Comment

Inherits:
Base::Comment show all
Defined in:
lib/rdoc_rubocop/lang/c/comment.rb,
lib/rdoc_rubocop/lang/c/comment/banner.rb,
lib/rdoc_rubocop/lang/c/comment/normal.rb,
lib/rdoc_rubocop/lang/c/comment/one_line.rb

Direct Known Subclasses

Banner, Normal, OneLine

Defined Under Namespace

Classes: Banner, Normal, OneLine

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base::Comment

#rdoc, #source_codes

Constructor Details

#initialize(comment_text, source_file, offset_begin, offset_end) ⇒ Comment

Returns a new instance of Comment.



28
29
30
31
32
33
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 28

def initialize(comment_text, source_file, offset_begin, offset_end)
  @comment_text = comment_text
  @source_file = source_file
  @offset_begin = offset_begin
  @offset_end = offset_end
end

Instance Attribute Details

#comment_textObject (readonly)

Returns the value of attribute comment_text.



7
8
9
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 7

def comment_text
  @comment_text
end

#offset_beginObject (readonly)

Returns the value of attribute offset_begin.



9
10
11
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 9

def offset_begin
  @offset_begin
end

#offset_endObject (readonly)

Returns the value of attribute offset_end.



10
11
12
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 10

def offset_end
  @offset_end
end

#source_fileObject (readonly)

Returns the value of attribute source_file.



8
9
10
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 8

def source_file
  @source_file
end

Class Method Details

.build(comment_text, source_file, offset_begin, offset_end) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 12

def self.build(comment_text, source_file, offset_begin, offset_end)
  body = comment_text.dup
  first_line = body.slice!(/\A.*\R/)

  klass =
    if first_line.nil?
      Comment::OneLine
    elsif first_line.match?(%r(^/\*[\x21-\x2f\x3a-\x3f])) || !body.match?(/\A *\*/)
      Comment::Banner
    else
      Comment::Normal
    end

  klass.new(comment_text, source_file, offset_begin, offset_end)
end

Instance Method Details

#lengthObject

def corrected_text end



38
39
40
# File 'lib/rdoc_rubocop/lang/c/comment.rb', line 38

def length
  @offset_end - @offset_begin
end