Class: SlimLint::Corrector
- Inherits:
-
Object
- Object
- SlimLint::Corrector
- Defined in:
- lib/slim_lint/corrector.rb
Overview
Applies the corrections attached to a set of lints to a document's source, producing the corrected source text.
Instance Method Summary collapse
-
#correct(lints) ⇒ String
Applies every correctable lint's correction to the document's source and marks each applied lint as corrected.
-
#initialize(document) ⇒ Corrector
constructor
A new instance of Corrector.
Constructor Details
#initialize(document) ⇒ Corrector
Returns a new instance of Corrector.
8 9 10 |
# File 'lib/slim_lint/corrector.rb', line 8 def initialize(document) @document = document end |
Instance Method Details
#correct(lints) ⇒ String
Applies every correctable lint's correction to the document's source and marks each applied lint as corrected.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/slim_lint/corrector.rb', line 17 def correct(lints) lines = @document.source_lines.dup lints.select(&:correctable?).group_by(&:line).each do |line_number, line_lints| index = line_number - 1 next unless lines[index] line_lints.each do |lint| lines[index] = lint.correction.call(lines[index]) lint.corrected = true end end corrected_source(lines) end |