Class: Spoom::Deadcode::Location

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Includes:
Comparable
Defined in:
lib/spoom/deadcode/location.rb

Defined Under Namespace

Classes: LocationError

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, start_line, start_column, end_line, end_column) ⇒ Location

Returns a new instance of Location.



37
38
39
40
41
42
43
# File 'lib/spoom/deadcode/location.rb', line 37

def initialize(file, start_line, start_column, end_line, end_column)
  @file = file
  @start_line = start_line
  @start_column = start_column
  @end_line = end_line
  @end_column = end_column
end

Instance Attribute Details

#end_columnObject (readonly)

Returns the value of attribute end_column.



26
27
28
# File 'lib/spoom/deadcode/location.rb', line 26

def end_column
  @end_column
end

#end_lineObject (readonly)

Returns the value of attribute end_line.



26
27
28
# File 'lib/spoom/deadcode/location.rb', line 26

def end_line
  @end_line
end

#fileObject (readonly)

Returns the value of attribute file.



23
24
25
# File 'lib/spoom/deadcode/location.rb', line 23

def file
  @file
end

#start_columnObject (readonly)

Returns the value of attribute start_column.



26
27
28
# File 'lib/spoom/deadcode/location.rb', line 26

def start_column
  @start_column
end

#start_lineObject (readonly)

Returns the value of attribute start_line.



26
27
28
# File 'lib/spoom/deadcode/location.rb', line 26

def start_line
  @start_line
end

Class Method Details

.from_syntax_tree(file, location) ⇒ Object



17
18
19
# File 'lib/spoom/deadcode/location.rb', line 17

def from_syntax_tree(file, location)
  new(file, location.start_line, location.start_column, location.end_line, location.end_column)
end

Instance Method Details

#<=>(other) ⇒ Object



46
47
48
49
50
# File 'lib/spoom/deadcode/location.rb', line 46

def <=>(other)
  return nil unless Location === other

  to_s <=> other.to_s
end

#to_sObject



53
54
55
# File 'lib/spoom/deadcode/location.rb', line 53

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