Class: BetterHtml::Tokenizer::Location
- Inherits:
-
Object
- Object
- BetterHtml::Tokenizer::Location
- Defined in:
- lib/better_html/tokenizer/location.rb
Instance Attribute Summary collapse
-
#document ⇒ Object
Returns the value of attribute document.
-
#start ⇒ Object
Returns the value of attribute start.
-
#stop ⇒ Object
Returns the value of attribute stop.
Instance Method Summary collapse
- #column ⇒ Object
-
#initialize(document, start, stop) ⇒ Location
constructor
A new instance of Location.
- #line ⇒ Object
- #line_range ⇒ Object
- #line_source_with_underline ⇒ Object
- #range ⇒ Object
- #source ⇒ Object
- #start_column ⇒ Object
- #start_line ⇒ Object
- #stop_column ⇒ Object
- #stop_line ⇒ Object
Constructor Details
#initialize(document, start, stop) ⇒ Location
Returns a new instance of Location.
6 7 8 9 10 11 12 13 14 |
# File 'lib/better_html/tokenizer/location.rb', line 6 def initialize(document, start, stop) raise ArgumentError, "start location #{start} is out of range for document of size #{document.size}" if start > document.size raise ArgumentError, "stop location #{stop} is out of range for document of size #{document.size}" if stop > document.size raise ArgumentError, "end of range must be greater than start of range (#{stop} < #{start})" if stop < start @document = document @start = start @stop = stop end |
Instance Attribute Details
#document ⇒ Object
Returns the value of attribute document.
4 5 6 |
# File 'lib/better_html/tokenizer/location.rb', line 4 def document @document end |
#start ⇒ Object
Returns the value of attribute start.
4 5 6 |
# File 'lib/better_html/tokenizer/location.rb', line 4 def start @start end |
#stop ⇒ Object
Returns the value of attribute stop.
4 5 6 |
# File 'lib/better_html/tokenizer/location.rb', line 4 def stop @stop end |
Instance Method Details
#column ⇒ Object
44 45 46 |
# File 'lib/better_html/tokenizer/location.rb', line 44 def column start_column end |
#line ⇒ Object
32 33 34 |
# File 'lib/better_html/tokenizer/location.rb', line 32 def line start_line end |
#line_range ⇒ Object
20 21 22 |
# File 'lib/better_html/tokenizer/location.rb', line 20 def line_range Range.new(start_line, stop_line) end |
#line_source_with_underline ⇒ Object
52 53 54 55 56 57 58 |
# File 'lib/better_html/tokenizer/location.rb', line 52 def line_source_with_underline line_content = extract_line(line: start_line) spaces = line_content.scan(/\A\s*/).first column_without_spaces = [column - spaces.length, 0].max underscore_length = [[stop - start + 1, line_content.length - column_without_spaces].min, 1].max "#{line_content.gsub(/\A\s*/, '')}\n#{' ' * column_without_spaces}#{'^' * underscore_length}" end |
#range ⇒ Object
16 17 18 |
# File 'lib/better_html/tokenizer/location.rb', line 16 def range Range.new(start, stop) end |
#source ⇒ Object
24 25 26 |
# File 'lib/better_html/tokenizer/location.rb', line 24 def source @document[range] end |
#start_column ⇒ Object
40 41 42 |
# File 'lib/better_html/tokenizer/location.rb', line 40 def start_column @start_column ||= calculate_column(start) end |
#start_line ⇒ Object
28 29 30 |
# File 'lib/better_html/tokenizer/location.rb', line 28 def start_line @start_line ||= calculate_line(start) end |
#stop_column ⇒ Object
48 49 50 |
# File 'lib/better_html/tokenizer/location.rb', line 48 def stop_column @stop_column ||= calculate_column(stop) end |
#stop_line ⇒ Object
36 37 38 |
# File 'lib/better_html/tokenizer/location.rb', line 36 def stop_line @stop_line ||= calculate_line(stop) end |