Class: ArchSpec::SourceLocation

Inherits:
Data
  • Object
show all
Defined in:
lib/archspec/source_location.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column

Returns:

  • (Object)

    the current value of column



6
7
8
# File 'lib/archspec/source_location.rb', line 6

def column
  @column
end

#end_columnObject (readonly)

Returns the value of attribute end_column

Returns:

  • (Object)

    the current value of end_column



6
7
8
# File 'lib/archspec/source_location.rb', line 6

def end_column
  @end_column
end

#end_lineObject (readonly)

Returns the value of attribute end_line

Returns:

  • (Object)

    the current value of end_line



6
7
8
# File 'lib/archspec/source_location.rb', line 6

def end_line
  @end_line
end

#lineObject (readonly)

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



6
7
8
# File 'lib/archspec/source_location.rb', line 6

def line
  @line
end

#pathObject (readonly)

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



6
7
8
# File 'lib/archspec/source_location.rb', line 6

def path
  @path
end

Class Method Details

.from_prism(path, location) ⇒ Object



7
8
9
# File 'lib/archspec/source_location.rb', line 7

def self.from_prism(path, location)
  new(path, location.start_line, location.start_column + 1, location.end_line, location.end_column + 1)
end

.point(path, line, column) ⇒ Object

A zero-width location for diagnostics that point at a file rather than a span of code.



13
14
15
# File 'lib/archspec/source_location.rb', line 13

def self.point(path, line, column)
  new(path, line, column, line, column)
end

Instance Method Details

#relative_path(root) ⇒ Object



17
18
19
20
21
# File 'lib/archspec/source_location.rb', line 17

def relative_path(root)
  Pathname(path).relative_path_from(Pathname(root)).to_s
rescue ArgumentError
  path
end