Class: ERBLint::OffsetCorrector
- Inherits:
-
Object
- Object
- ERBLint::OffsetCorrector
- Defined in:
- lib/erb_lint/offset_corrector.rb
Instance Method Summary collapse
- #bound(pos) ⇒ Object
-
#initialize(processed_source, corrector, offset, bound_range) ⇒ OffsetCorrector
constructor
A new instance of OffsetCorrector.
- #insert_after(range, content) ⇒ Object
- #insert_before(range, content) ⇒ Object
- #range_with_offset(range) ⇒ Object
- #remove(range) ⇒ Object
- #remove_leading(range, size) ⇒ Object
- #remove_preceding(range, size) ⇒ Object
- #remove_trailing(range, size) ⇒ Object
- #replace(range, content) ⇒ Object
Constructor Details
#initialize(processed_source, corrector, offset, bound_range) ⇒ OffsetCorrector
Returns a new instance of OffsetCorrector.
5 6 7 8 9 10 |
# File 'lib/erb_lint/offset_corrector.rb', line 5 def initialize(processed_source, corrector, offset, bound_range) @processed_source = processed_source @corrector = corrector @offset = offset @bound_range = bound_range end |
Instance Method Details
#bound(pos) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/erb_lint/offset_corrector.rb', line 47 def bound(pos) [ [pos, @bound_range.begin_pos].max, @bound_range.end_pos - 1 ].min end |
#insert_after(range, content) ⇒ Object
20 21 22 |
# File 'lib/erb_lint/offset_corrector.rb', line 20 def insert_after(range, content) @corrector.insert_after(range_with_offset(range), content) end |
#insert_before(range, content) ⇒ Object
16 17 18 |
# File 'lib/erb_lint/offset_corrector.rb', line 16 def insert_before(range, content) @corrector.insert_before(range_with_offset(range), content) end |
#range_with_offset(range) ⇒ Object
40 41 42 43 44 45 |
# File 'lib/erb_lint/offset_corrector.rb', line 40 def range_with_offset(range) @processed_source.to_source_range( bound(@offset + range.begin_pos), bound(@offset + range.end_pos - 1), ) end |
#remove(range) ⇒ Object
12 13 14 |
# File 'lib/erb_lint/offset_corrector.rb', line 12 def remove(range) @corrector.remove(range_with_offset(range)) end |
#remove_leading(range, size) ⇒ Object
32 33 34 |
# File 'lib/erb_lint/offset_corrector.rb', line 32 def remove_leading(range, size) @corrector.remove_leading(range_with_offset(range), size) end |
#remove_preceding(range, size) ⇒ Object
28 29 30 |
# File 'lib/erb_lint/offset_corrector.rb', line 28 def remove_preceding(range, size) @corrector.remove_preceding(range_with_offset(range), size) end |
#remove_trailing(range, size) ⇒ Object
36 37 38 |
# File 'lib/erb_lint/offset_corrector.rb', line 36 def remove_trailing(range, size) @corrector.remove_trailing(range_with_offset(range), size) end |
#replace(range, content) ⇒ Object
24 25 26 |
# File 'lib/erb_lint/offset_corrector.rb', line 24 def replace(range, content) @corrector.replace(range_with_offset(range), content) end |