Class: ERBLint::Utils::OffsetCorrector
- Inherits:
-
Object
- Object
- ERBLint::Utils::OffsetCorrector
- Defined in:
- lib/erb_lint/utils/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(node_or_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.
6 7 8 9 10 11 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 6 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
49 50 51 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 49 def bound(pos) pos.clamp(@bound_range.min, @bound_range.max) end |
#insert_after(range, content) ⇒ Object
21 22 23 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 21 def insert_after(range, content) @corrector.insert_after(range_with_offset(range), content) end |
#insert_before(range, content) ⇒ Object
17 18 19 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 17 def insert_before(range, content) @corrector.insert_before(range_with_offset(range), content) end |
#range_with_offset(node_or_range) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 41 def range_with_offset(node_or_range) range = to_range(node_or_range) @processed_source.to_source_range( bound(@offset + range.begin_pos)..bound(@offset + (range.end_pos - 1)), ) end |
#remove(range) ⇒ Object
13 14 15 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 13 def remove(range) @corrector.remove(range_with_offset(range)) end |
#remove_leading(range, size) ⇒ Object
33 34 35 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 33 def remove_leading(range, size) @corrector.remove_leading(range_with_offset(range), size) end |
#remove_preceding(range, size) ⇒ Object
29 30 31 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 29 def remove_preceding(range, size) @corrector.remove_preceding(range_with_offset(range), size) end |
#remove_trailing(range, size) ⇒ Object
37 38 39 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 37 def remove_trailing(range, size) @corrector.remove_trailing(range_with_offset(range), size) end |
#replace(range, content) ⇒ Object
25 26 27 |
# File 'lib/erb_lint/utils/offset_corrector.rb', line 25 def replace(range, content) @corrector.replace(range_with_offset(range), content) end |