Class: RBI::Loc
Instance Attribute Summary collapse
-
#begin_column ⇒ Object
readonly
Returns the value of attribute begin_column.
-
#begin_line ⇒ Object
readonly
Returns the value of attribute begin_line.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil) ⇒ Loc
constructor
A new instance of Loc.
- #source ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(file: nil, begin_line: nil, end_line: nil, begin_column: nil, end_column: nil) ⇒ Loc
Returns a new instance of Loc.
38 39 40 41 42 43 44 |
# File 'lib/rbi/loc.rb', line 38 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)
Returns the value of attribute begin_column.
27 28 29 |
# File 'lib/rbi/loc.rb', line 27 def begin_column @begin_column end |
#begin_line ⇒ Object (readonly)
Returns the value of attribute begin_line.
27 28 29 |
# File 'lib/rbi/loc.rb', line 27 def begin_line @begin_line end |
#end_column ⇒ Object (readonly)
Returns the value of attribute end_column.
27 28 29 |
# File 'lib/rbi/loc.rb', line 27 def end_column @end_column end |
#end_line ⇒ Object (readonly)
Returns the value of attribute end_line.
27 28 29 |
# File 'lib/rbi/loc.rb', line 27 def end_line @end_line end |
#file ⇒ Object (readonly)
Returns the value of attribute file.
24 25 26 |
# File 'lib/rbi/loc.rb', line 24 def file @file end |
Class Method Details
.from_prism(file, prism_location) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/rbi/loc.rb', line 12 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
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/rbi/loc.rb', line 56 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
47 48 49 50 51 52 53 |
# File 'lib/rbi/loc.rb', line 47 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 |