class BetterHtml::Tokenizer::Location
Public Class Methods
new(buffer, begin_pos, end_pos)
click to toggle source
Calls superclass method
# File lib/better_html/tokenizer/location.rb, line 7 def initialize(buffer, begin_pos, end_pos) raise ArgumentError, 'first argument must be Parser::Source::Buffer' unless buffer.is_a?(::Parser::Source::Buffer) raise ArgumentError, "begin_pos location #{begin_pos} is out of range for document of size #{buffer.source.size}" if begin_pos > buffer.source.size raise ArgumentError, "end_pos location #{end_pos} is out of range for document of size #{buffer.source.size}" if (end_pos - 1) > buffer.source.size super(buffer, begin_pos, end_pos) end
Public Instance Methods
adjust(begin_pos: 0, end_pos: 0)
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 39 def adjust(begin_pos: 0, end_pos: 0) self.class.new(@source_buffer, @begin_pos + begin_pos, @end_pos + end_pos) end
begin()
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 51 def begin with(end_pos: @begin_pos) end
end()
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 55 def end with(begin_pos: @end_pos) end
line_range()
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 19 def line_range Range.new(start_line, stop_line) end
line_source_with_underline()
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 28 def line_source_with_underline spaces = source_line.scan(/\A\s*/).first column_without_spaces = [column - spaces.length, 0].max underscore_length = [[end_pos - begin_pos, source_line.length - column_without_spaces].min, 1].max "#{source_line.gsub(/\A\s*/, '')}\n#{' ' * column_without_spaces}#{'^' * underscore_length}" end
offset(offset)
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 47 def offset(offset) with(begin_pos: offset + @begin_pos, end_pos: offset + @end_pos) end
range()
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 15 def range Range.new(begin_pos, end_pos, true) end
resize(new_size)
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 43 def resize(new_size) with(end_pos: @begin_pos + new_size) end
with(begin_pos: @begin_pos, end_pos: @end_pos)
click to toggle source
# File lib/better_html/tokenizer/location.rb, line 35 def with(begin_pos: @begin_pos, end_pos: @end_pos) self.class.new(@source_buffer, begin_pos, end_pos) end