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)


89
90
91
92
93
94
95
# File 'lib/rubydex/location.rb', line 89

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

Instance Method Details

#comparable_valuesObject

Normalize to zero-based for comparison with Location

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



108
109
110
# File 'lib/rubydex/location.rb', line 108

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

#to_displayObject

Returns itself

: () -> DisplayLocation



101
102
103
# File 'lib/rubydex/location.rb', line 101

def to_display
  self
end

#to_sObject

: -> String



113
114
115
# File 'lib/rubydex/location.rb', line 113

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