Class: Rattler::Util::LineCounter
- Inherits:
-
Object
- Object
- Rattler::Util::LineCounter
- Defined in:
- lib/rattler/util/line_counter.rb
Overview
A LineCounter
takes a linear index into text and calculates line and column numbers.
Constant Summary collapse
- @@newline =
"\n"
- @@tab =
"\t"
Instance Method Summary collapse
-
#column(index) ⇒ Integer
Return the column number of the character at
index
. -
#initialize(source, options = {}) ⇒ LineCounter
constructor
Create a
Rattler::Util::LineCounter
object forsource
. -
#line(index) ⇒ Integer
Return the line number of the character at
index
.
Constructor Details
#initialize(source, options = {}) ⇒ LineCounter
Create a Rattler::Util::LineCounter
object for source
.
30 31 32 33 |
# File 'lib/rattler/util/line_counter.rb', line 30 def initialize(source, ={}) @source = source @tab_size = [:tab_size] || 8 end |
Instance Method Details
#column(index) ⇒ Integer
Return the column number of the character at index
. When a tab character is encountered the next tab stop is used for the column number of the character following the tab character.
50 51 52 53 |
# File 'lib/rattler/util/line_counter.rb', line 50 def column(index) count(index) return @column end |
#line(index) ⇒ Integer
Return the line number of the character at index
.
39 40 41 42 |
# File 'lib/rattler/util/line_counter.rb', line 39 def line(index) count(index) return @line end |