class ERBLint::Utils::OffsetCorrector
Public Class Methods
new(processed_source, corrector, offset, bound_range)
click to toggle source
# 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
Public Instance Methods
bound(pos)
click to toggle source
# File lib/erb_lint/utils/offset_corrector.rb, line 49 def bound(pos) [ [pos, @bound_range.min].max, @bound_range.max, ].min end
insert_after(range, content)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/erb_lint/utils/offset_corrector.rb, line 13 def remove(range) @corrector.remove(range_with_offset(range)) end
remove_leading(range, size)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/erb_lint/utils/offset_corrector.rb, line 25 def replace(range, content) @corrector.replace(range_with_offset(range), content) end
Private Instance Methods
to_range(node_or_range)
click to toggle source
# File lib/erb_lint/utils/offset_corrector.rb, line 58 def to_range(node_or_range) case node_or_range when ::RuboCop::AST::Node, ::Parser::Source::Comment node_or_range.loc.expression when ::Parser::Source::Range node_or_range else raise TypeError, "Expected a Parser::Source::Range, Comment or " \ "Rubocop::AST::Node, got #{node_or_range.class}" end end