Class: Spoom::Deadcode::Location
- Inherits:
-
Object
- Object
- Spoom::Deadcode::Location
- Extended by:
- T::Sig
- Includes:
- Comparable
- Defined in:
- lib/spoom/deadcode/location.rb
Defined Under Namespace
Classes: LocationError
Instance Attribute Summary collapse
-
#end_column ⇒ Object
readonly
Returns the value of attribute end_column.
-
#end_line ⇒ Object
readonly
Returns the value of attribute end_line.
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#start_column ⇒ Object
readonly
Returns the value of attribute start_column.
-
#start_line ⇒ Object
readonly
Returns the value of attribute start_line.
Class Method Summary collapse
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #include?(other) ⇒ Boolean
-
#initialize(file, start_line, start_column, end_line, end_column) ⇒ Location
constructor
A new instance of Location.
- #to_s ⇒ Object
Constructor Details
#initialize(file, start_line, start_column, end_line, end_column) ⇒ Location
Returns a new instance of Location.
54 55 56 57 58 59 60 |
# File 'lib/spoom/deadcode/location.rb', line 54 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_column ⇒ Object (readonly)
Returns the value of attribute end_column.
43 44 45 |
# File 'lib/spoom/deadcode/location.rb', line 43 def end_column @end_column end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
43 44 45 |
# File 'lib/spoom/deadcode/location.rb', line 43 def end_line @end_line end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
40 41 42 |
# File 'lib/spoom/deadcode/location.rb', line 40 def file @file end |
#start_column ⇒ Object (readonly)
Returns the value of attribute start_column.
43 44 45 |
# File 'lib/spoom/deadcode/location.rb', line 43 def start_column @start_column end |
#start_line ⇒ Object (readonly)
Returns the value of attribute start_line.
43 44 45 |
# File 'lib/spoom/deadcode/location.rb', line 43 def start_line @start_line end |
Class Method Details
.from_string(location_string) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/spoom/deadcode/location.rb', line 17 def from_string(location_string) file, rest = location_string.split(":", 2) raise LocationError, "Invalid location string: #{location_string}" unless file && rest start_line, rest = rest.split(":", 2) raise LocationError, "Invalid location string: #{location_string}" unless start_line && rest start_column, rest = rest.split("-", 2) raise LocationError, "Invalid location string: #{location_string}" unless start_column && rest end_line, end_column = rest.split(":", 2) raise LocationError, "Invalid location string: #{location_string}" unless end_line && end_column new(file, start_line.to_i, start_column.to_i, end_line.to_i, end_column.to_i) end |
.from_syntax_tree(file, location) ⇒ Object
34 35 36 |
# File 'lib/spoom/deadcode/location.rb', line 34 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
74 75 76 77 78 |
# File 'lib/spoom/deadcode/location.rb', line 74 def <=>(other) return unless Location === other to_s <=> other.to_s end |
#include?(other) ⇒ Boolean
63 64 65 66 67 68 69 70 71 |
# File 'lib/spoom/deadcode/location.rb', line 63 def include?(other) return false unless @file == other.file return false if @start_line > other.start_line return false if @start_line == other.start_line && @start_column > other.start_column return false if @end_line < other.end_line return false if @end_line == other.end_line && @end_column < other.end_column true end |
#to_s ⇒ Object
81 82 83 |
# File 'lib/spoom/deadcode/location.rb', line 81 def to_s "#{@file}:#{@start_line}:#{@start_column}-#{@end_line}:#{@end_column}" end |