Class: PlatformosCheck::Position
- Inherits:
-
Object
- Object
- PlatformosCheck::Position
- Includes:
- PositionHelper
- Defined in:
- lib/platformos_check/position.rb
Instance Attribute Summary collapse
-
#contents ⇒ Object
readonly
Returns the value of attribute contents.
Instance Method Summary collapse
- #content_line_count ⇒ Object
- #end_column ⇒ Object
-
#end_index ⇒ Object
0-indexed, exclusive.
-
#end_row ⇒ Object
0-indexed, exclusive (both taken together are) therefore you might end up on a newline character or the next line.
-
#initialize(needle_arg, contents_arg, line_number_1_indexed: nil, node_markup: nil, node_markup_offset: 0) ⇒ Position
constructor
A new instance of Position.
-
#start_column ⇒ Object
0-indexed, inclusive.
-
#start_index ⇒ Object
0-indexed, inclusive.
- #start_line_offset ⇒ Object
- #start_offset ⇒ Object
-
#start_row ⇒ Object
0-indexed, inclusive.
- #strict_position ⇒ Object
Methods included from PositionHelper
#bounded, #from_index_to_row_column, #from_row_column_to_index
Constructor Details
#initialize(needle_arg, contents_arg, line_number_1_indexed: nil, node_markup: nil, node_markup_offset: 0) ⇒ Position
Returns a new instance of Position.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/platformos_check/position.rb', line 9 def initialize( needle_arg, contents_arg, line_number_1_indexed: nil, node_markup: nil, node_markup_offset: 0 # the index of markup inside the node_markup ) @needle = needle_arg @contents = if contents_arg.is_a?(String) && !contents_arg.empty? contents_arg else '' end @line_number_1_indexed = line_number_1_indexed @node_markup_offset = node_markup_offset @node_markup = node_markup end |
Instance Attribute Details
#contents ⇒ Object (readonly)
Returns the value of attribute contents.
7 8 9 |
# File 'lib/platformos_check/position.rb', line 7 def contents @contents end |
Instance Method Details
#content_line_count ⇒ Object
75 76 77 |
# File 'lib/platformos_check/position.rb', line 75 def content_line_count @content_line_count ||= contents.count("\n") end |
#end_column ⇒ Object
71 72 73 |
# File 'lib/platformos_check/position.rb', line 71 def end_column strict_position.end_column end |
#end_index ⇒ Object
0-indexed, exclusive
51 52 53 |
# File 'lib/platformos_check/position.rb', line 51 def end_index strict_position.end_index end |
#end_row ⇒ Object
0-indexed, exclusive (both taken together are) therefore you might end up on a newline character or the next line
67 68 69 |
# File 'lib/platformos_check/position.rb', line 67 def end_row strict_position.end_row end |
#start_column ⇒ Object
0-indexed, inclusive
61 62 63 |
# File 'lib/platformos_check/position.rb', line 61 def start_column strict_position.start_column end |
#start_index ⇒ Object
0-indexed, inclusive
46 47 48 |
# File 'lib/platformos_check/position.rb', line 46 def start_index contents.index(needle, start_offset) end |
#start_line_offset ⇒ Object
29 30 31 |
# File 'lib/platformos_check/position.rb', line 29 def start_line_offset @start_line_offset ||= from_row_column_to_index(contents, line_number, 0) end |
#start_offset ⇒ Object
33 34 35 |
# File 'lib/platformos_check/position.rb', line 33 def start_offset @start_offset ||= compute_start_offset end |
#start_row ⇒ Object
0-indexed, inclusive
56 57 58 |
# File 'lib/platformos_check/position.rb', line 56 def start_row strict_position.start_row end |
#strict_position ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/platformos_check/position.rb', line 37 def strict_position @strict_position ||= StrictPosition.new( needle, contents, start_index ) end |