Class: ThemeCheck::Position

Inherits:
Object
  • Object
show all
Includes:
PositionHelper
Defined in:
lib/theme_check/position.rb

Instance Method Summary collapse

Methods included from PositionHelper

#bounded, #from_index_to_row_column, #from_row_column_to_index

Constructor Details

#initialize(needle, contents, line_number_1_indexed) ⇒ Position

Returns a new instance of Position.



7
8
9
10
11
12
13
# File 'lib/theme_check/position.rb', line 7

def initialize(needle, contents, line_number_1_indexed)
  @needle = needle
  @contents = contents
  @line_number_1_indexed = line_number_1_indexed
  @start_row_column = nil
  @end_row_column = nil
end

Instance Method Details

#end_columnObject



41
42
43
# File 'lib/theme_check/position.rb', line 41

def end_column
  end_row_column[1]
end

#end_indexObject

0-indexed, exclusive



25
26
27
# File 'lib/theme_check/position.rb', line 25

def end_index
  start_index + needle.size
end

#end_rowObject



37
38
39
# File 'lib/theme_check/position.rb', line 37

def end_row
  end_row_column[0]
end

#start_columnObject



33
34
35
# File 'lib/theme_check/position.rb', line 33

def start_column
  start_row_column[1]
end

#start_indexObject

0-indexed, inclusive



20
21
22
# File 'lib/theme_check/position.rb', line 20

def start_index
  contents.index(needle, start_line_index) || start_line_index
end

#start_line_indexObject



15
16
17
# File 'lib/theme_check/position.rb', line 15

def start_line_index
  from_row_column_to_index(contents, line_number, 0)
end

#start_rowObject



29
30
31
# File 'lib/theme_check/position.rb', line 29

def start_row
  start_row_column[0]
end