Class: Slimi::Range
- Inherits:
-
Object
- Object
- Slimi::Range
- Defined in:
- lib/slimi/range.rb
Overview
Get line-based information from source code and its index.
Instance Method Summary collapse
-
#column ⇒ Integer
1-indexed column index.
-
#initialize(index:, source:) ⇒ Range
constructor
A new instance of Range.
- #line ⇒ Object
-
#line_number ⇒ Integer
1-indexed line index.
Constructor Details
#initialize(index:, source:) ⇒ Range
Returns a new instance of Range.
8 9 10 11 |
# File 'lib/slimi/range.rb', line 8 def initialize(index:, source:) @index = index @source = source end |
Instance Method Details
#column ⇒ Integer
Returns 1-indexed column index.
14 15 16 |
# File 'lib/slimi/range.rb', line 14 def column (@index - line_beginning_index) + 1 end |
#line ⇒ Object
18 19 20 |
# File 'lib/slimi/range.rb', line 18 def line @source[line_beginning_index...line_ending_index] end |
#line_number ⇒ Integer
Returns 1-indexed line index.
23 24 25 |
# File 'lib/slimi/range.rb', line 23 def line_number @source[0..@index].scan(/^/).length end |