Class: ThemeCheck::StrictPosition

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

Overview

This method is stricter than Position in the sense that it doesn’t accept invalid inputs. Makes for code that is easier to understand.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PositionHelper

#bounded, #from_index_to_row_column, #from_row_column_to_index

Constructor Details

#initialize(needle, contents, start_index) ⇒ StrictPosition

Returns a new instance of StrictPosition.

Raises:

  • (ArgumentError)


125
126
127
128
129
130
131
132
133
134
135
# File 'lib/theme_check/position.rb', line 125

def initialize(needle, contents, start_index)
  raise ArgumentError, 'Bad start_index' unless start_index.is_a?(Integer)
  raise ArgumentError, 'Bad contents' unless contents.is_a?(String)
  raise ArgumentError, 'Bad needle' unless needle.is_a?(String) || !contents.index(needle, start_index)

  @needle = needle
  @contents = contents
  @start_index = start_index
  @start_row_column = nil
  @end_row_column = nil
end

Instance Attribute Details

#contentsObject (readonly)

Returns the value of attribute contents.



123
124
125
# File 'lib/theme_check/position.rb', line 123

def contents
  @contents
end

#needleObject (readonly)

Returns the value of attribute needle.



123
124
125
# File 'lib/theme_check/position.rb', line 123

def needle
  @needle
end

Instance Method Details

#end_columnObject



159
160
161
# File 'lib/theme_check/position.rb', line 159

def end_column
  end_row_column[1]
end

#end_indexObject

0-indexed, exclusive



143
144
145
# File 'lib/theme_check/position.rb', line 143

def end_index
  start_index + needle.size
end

#end_rowObject



155
156
157
# File 'lib/theme_check/position.rb', line 155

def end_row
  end_row_column[0]
end

#start_columnObject



151
152
153
# File 'lib/theme_check/position.rb', line 151

def start_column
  start_row_column[1]
end

#start_indexObject

0-indexed, inclusive



138
139
140
# File 'lib/theme_check/position.rb', line 138

def start_index
  @contents.index(needle, @start_index)
end

#start_rowObject



147
148
149
# File 'lib/theme_check/position.rb', line 147

def start_row
  start_row_column[0]
end