Class: RDocRuboCop::Lang::Ruby::Corrector

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_file) ⇒ Corrector

Returns a new instance of Corrector.



9
10
11
12
# File 'lib/rdoc_rubocop/lang/ruby/corrector.rb', line 9

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.



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

def corrected_source
  @corrected_source
end

Instance Method Details

#correctObject



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

def correct
  source_lines = @source_file.source.lines

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

    index = comment.lineno[0] - 1
    number_of_lines = comment.number_of_lines
    source_lines[index, number_of_lines] = comment.corrected_text
  end

  @corrected_source = source_lines.join
end