Class: RDocRuboCop::Lang::C::Corrector

Inherits:
Object
  • Object
show all
Defined in:
lib/rdoc_rubocop/lang/c/corrector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file) ⇒ Corrector

Returns a new instance of Corrector.



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

def initialize(source_file)
  @source_file = source_file
  @corrected_source = nil
end

Instance Attribute Details

#corrected_sourceObject (readonly)

Returns the value of attribute corrected_source.



5
6
7
# File 'lib/rdoc_rubocop/lang/c/corrector.rb', line 5

def corrected_source
  @corrected_source
end

Instance Method Details

#correctObject



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rdoc_rubocop/lang/c/corrector.rb', line 12

def correct
  @corrected_source = @source_file.source.dup

  @source_file.comments.reverse_each do |comment|
    next if comment.source_codes.empty?

    index = comment.offset_begin
    length = comment.length
    @corrected_source[index, length] = comment.corrected_text
  end
end