Class: PlatformosCheck::StrictPosition
- Inherits:
-
Object
- Object
- PlatformosCheck::StrictPosition
- Includes:
- PositionHelper
- Defined in:
- lib/platformos_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
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
-
#needle ⇒ Object
readonly
Returns the value of attribute needle.
Instance Method Summary collapse
- #end_column ⇒ Object
-
#end_index ⇒ Object
0-indexed, exclusive.
- #end_row ⇒ Object
-
#initialize(needle, contents, start_index) ⇒ StrictPosition
constructor
A new instance of StrictPosition.
- #start_column ⇒ Object
-
#start_index ⇒ Object
0-indexed, inclusive.
- #start_row ⇒ Object
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.
128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/platformos_check/position.rb', line 128 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
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
126 127 128 |
# File 'lib/platformos_check/position.rb', line 126 def contents @contents end |
#needle ⇒ Object (readonly)
Returns the value of attribute needle.
126 127 128 |
# File 'lib/platformos_check/position.rb', line 126 def needle @needle end |
Instance Method Details
#end_column ⇒ Object
162 163 164 |
# File 'lib/platformos_check/position.rb', line 162 def end_column end_row_column[1] end |
#end_index ⇒ Object
0-indexed, exclusive
146 147 148 |
# File 'lib/platformos_check/position.rb', line 146 def end_index start_index + needle.size end |
#end_row ⇒ Object
158 159 160 |
# File 'lib/platformos_check/position.rb', line 158 def end_row end_row_column[0] end |
#start_column ⇒ Object
154 155 156 |
# File 'lib/platformos_check/position.rb', line 154 def start_column start_row_column[1] end |
#start_index ⇒ Object
0-indexed, inclusive
141 142 143 |
# File 'lib/platformos_check/position.rb', line 141 def start_index @contents.index(needle, @start_index) end |
#start_row ⇒ Object
150 151 152 |
# File 'lib/platformos_check/position.rb', line 150 def start_row start_row_column[0] end |