Class: RBI::Loc
- Inherits:
-
Object
- Object
- RBI::Loc
- Defined in:
- lib/rbi/loc.rb
Instance Attribute Summary collapse
-
#begin_column ⇒ Object
readonly
: Integer?.
-
#begin_line ⇒ Object
readonly
: Integer?.
-
#end_column ⇒ Object
readonly
: Integer?.
-
#end_line ⇒ Object
readonly
: Integer?.
-
#file ⇒ Object
readonly
: String?.
Class Method Summary collapse
-
.from_prism(file, prism_location) ⇒ Object
: (String file, Prism::Location prism_location) -> Loc.
Instance Method Summary collapse
-
#initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil) ⇒ Loc
constructor
: (?file: String?, ?begin_line: Integer?, ?end_line: Integer?, ?begin_column: Integer?, ?end_column: Integer?) -> void.
-
#source ⇒ Object
: -> String?.
-
#to_s ⇒ Object
: -> String.
Constructor Details
#initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil) ⇒ Loc
: (?file: String?, ?begin_line: Integer?, ?end_line: Integer?, ?begin_column: Integer?, ?end_column: Integer?) -> void
26 27 28 29 30 31 32 |
# File 'lib/rbi/loc.rb', line 26 def initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil) @file = file @begin_line = begin_line @end_line = end_line @begin_column = begin_column @end_column = end_column end |
Instance Attribute Details
#begin_column ⇒ Object (readonly)
: Integer?
23 24 25 |
# File 'lib/rbi/loc.rb', line 23 def begin_column @begin_column end |
#begin_line ⇒ Object (readonly)
: Integer?
23 24 25 |
# File 'lib/rbi/loc.rb', line 23 def begin_line @begin_line end |
#end_column ⇒ Object (readonly)
: Integer?
23 24 25 |
# File 'lib/rbi/loc.rb', line 23 def end_column @end_column end |
#end_line ⇒ Object (readonly)
: Integer?
23 24 25 |
# File 'lib/rbi/loc.rb', line 23 def end_line @end_line end |
#file ⇒ Object (readonly)
: String?
20 21 22 |
# File 'lib/rbi/loc.rb', line 20 def file @file end |
Class Method Details
.from_prism(file, prism_location) ⇒ Object
: (String file, Prism::Location prism_location) -> Loc
8 9 10 11 12 13 14 15 16 |
# File 'lib/rbi/loc.rb', line 8 def from_prism(file, prism_location) new( file: file, begin_line: prism_location.start_line, end_line: prism_location.end_line, begin_column: prism_location.start_column, end_column: prism_location.end_column, ) end |
Instance Method Details
#source ⇒ Object
: -> String?
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rbi/loc.rb', line 44 def source file = self.file return unless file return unless ::File.file?(file) return ::File.read(file) unless begin_line && end_line string = String.new ::File.foreach(file).with_index do |line, line_number| string << line if line_number + 1 >= begin_line && line_number + 1 <= end_line end string end |
#to_s ⇒ Object
: -> String
35 36 37 38 39 40 41 |
# File 'lib/rbi/loc.rb', line 35 def to_s if end_line && end_column "#{file}:#{begin_line}:#{begin_column}-#{end_line}:#{end_column}" else "#{file}:#{begin_line}:#{begin_column}" end end |