Class: Rubydex::DisplayLocation

Inherits:
Location
  • Object
show all
Defined in:
lib/rubydex/location.rb

Overview

A one based location intended for display purposes. This is what should be used when displaying a location to users, like in CLIs

Instance Attribute Summary

Attributes inherited from Location

#end_column, #end_line, #start_column, #start_line, #uri

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Location

#<=>, #initialize, #to_file_path

Constructor Details

This class inherits a constructor from Rubydex::Location

Class Method Details

.from_prism(prism_location, uri:) ⇒ Object

: (Prism::Location prism_location, uri: String) -> Location

Raises:

  • (NotImplementedError)


86
87
88
89
90
91
92
# File 'lib/rubydex/location.rb', line 86

def from_prism(prism_location, uri:)
  raise NotImplementedError, <<~MESSAGE
    Cannot convert Prism::Location directly to a Rubydex::DisplayLocation.
    Start with `Rubydex::Location.from_prism(...)` and then convert the resulting
    location with `to_display`
  MESSAGE
end

Instance Method Details

#comparable_valuesObject

Normalize to zero-based for comparison with Location

: () -> [String, Integer, Integer, Integer, Integer]



105
106
107
# File 'lib/rubydex/location.rb', line 105

def comparable_values
  [@uri, @start_line - 1, @start_column - 1, @end_line - 1, @end_column - 1]
end

#to_displayObject

Returns itself

: () -> DisplayLocation



98
99
100
# File 'lib/rubydex/location.rb', line 98

def to_display
  self
end

#to_sObject

: -> String



110
111
112
# File 'lib/rubydex/location.rb', line 110

def to_s
  "#{to_file_path}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}"
end