Module: Walrat::LocationTracking

Included in:
ArrayResult, MatchDataWrapper, Node, ParseError, SkippedSubstringException, StringResult
Defined in:
lib/walrat/location_tracking.rb

Overview

Methods for embedding location information in objects returned (or exceptions raised) from parse methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#outer_endObject

For occasions where a single item must serve as a carrier for array-like information (that is, its own start, end and source_text, as well as the “outer” equivalents). This can happen where a single node appears in a list context surrounded only by skipped content.



35
36
37
# File 'lib/walrat/location_tracking.rb', line 35

def outer_end
  @outer_end
end

#outer_source_textObject

For occasions where a single item must serve as a carrier for array-like information (that is, its own start, end and source_text, as well as the “outer” equivalents). This can happen where a single node appears in a list context surrounded only by skipped content.



35
36
37
# File 'lib/walrat/location_tracking.rb', line 35

def outer_source_text
  @outer_source_text
end

#outer_startObject

For occasions where a single item must serve as a carrier for array-like information (that is, its own start, end and source_text, as well as the “outer” equivalents). This can happen where a single node appears in a list context surrounded only by skipped content.



35
36
37
# File 'lib/walrat/location_tracking.rb', line 35

def outer_start
  @outer_start
end

#source_textObject

Returns the value of attribute source_text.



29
30
31
# File 'lib/walrat/location_tracking.rb', line 29

def source_text
  @source_text
end

Instance Method Details

#column_endObject



94
95
96
# File 'lib/walrat/location_tracking.rb', line 94

def column_end
  @column_end || 0
end

#column_end=(column_end) ⇒ Object



90
91
92
# File 'lib/walrat/location_tracking.rb', line 90

def column_end=(column_end)
  @column_end = column_end.to_i
end

#column_startObject

Returns 0 if @column_start is nil (for ease of use, users of classes that mix-in this module don’t have to worry about special casing nil values).



51
52
53
# File 'lib/walrat/location_tracking.rb', line 51

def column_start
  @column_start || 0
end

#column_start=(column_start) ⇒ Object

Sets @column_start to col. Sets @column_start to 0 if passed nil (for ease of use, users of classes that mix-in this module don’t have to worry about special casing nil values).



45
46
47
# File 'lib/walrat/location_tracking.rb', line 45

def column_start=(column_start)
  @column_start = column_start.to_i
end

#endObject

Convenience method for getting both line_end and column_end at once.



99
100
101
# File 'lib/walrat/location_tracking.rb', line 99

def end
  [self.line_end, self.column_end]
end

#end=(array) ⇒ Object

Convenience method for setting both line_end and column_end at once.

Raises:

  • (ArgumentError)


104
105
106
107
108
109
# File 'lib/walrat/location_tracking.rb', line 104

def end=(array)
  raise ArgumentError if array.nil?
  raise ArgumentError if array.length != 2
  self.line_end   = array[0]
  self.column_end = array[1]
end

#line_endObject



86
87
88
# File 'lib/walrat/location_tracking.rb', line 86

def line_end
  @line_end || 0
end

#line_end=(line_end) ⇒ Object



82
83
84
# File 'lib/walrat/location_tracking.rb', line 82

def line_end=(line_end)
  @line_end = line_end.to_i
end

#line_startObject

Returns 0 if @line_start is nil (for ease of use, users of classes that mix-in this module don’t have to worry about special casing nil values).



65
66
67
# File 'lib/walrat/location_tracking.rb', line 65

def line_start
  @line_start || 0
end

#line_start=(line_start) ⇒ Object

Sets @line_start to line. Sets @line_start to 0 if passed nil (for ease of use, users of classes that mix-in this module don’t have to worry about special casing nil values).



59
60
61
# File 'lib/walrat/location_tracking.rb', line 59

def line_start=(line_start)
  @line_start = line_start.to_i
end

#rightmost?(other) ⇒ Boolean

Given another object that responds to column_end and line_end, returns true if the receiver is rightmost or equal. If the other object is farther to the right returns false.

Returns:

  • (Boolean)


114
115
116
117
118
119
120
121
122
123
124
# File 'lib/walrat/location_tracking.rb', line 114

def rightmost? other
  if self.line_end > other.line_end
    true
  elsif other.line_end > self.line_end
    false
  elsif self.column_end >= other.column_end
    true
  else
    false
  end
end

#startObject

Convenience method for getting both line_start and column_start at once.



70
71
72
# File 'lib/walrat/location_tracking.rb', line 70

def start
  [self.line_start, self.column_start]
end

#start=(array) ⇒ Object

Convenience method for setting both line_start and column_start at once.

Raises:

  • (ArgumentError)


75
76
77
78
79
80
# File 'lib/walrat/location_tracking.rb', line 75

def start=(array)
  raise ArgumentError if array.nil?
  raise ArgumentError if array.length != 2
  self.line_start    = array[0]
  self.column_start  = array[1]
end