Class: Rucoa::Range
- Inherits:
-
Object
- Object
- Rucoa::Range
- Defined in:
- lib/rucoa/range.rb
Instance Attribute Summary collapse
- #beginning ⇒ Rucoa::Position readonly
- #ending ⇒ Rucoa::Position readonly
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Boolean
- #contain?(range) ⇒ Boolean
- #include?(position) ⇒ Boolean
-
#initialize(beginning, ending, including_ending: true) ⇒ Range
constructor
A new instance of Range.
- #to_vscode_range ⇒ Hash
Constructor Details
#initialize(beginning, ending, including_ending: true) ⇒ Range
Returns a new instance of Range.
34 35 36 37 38 39 40 41 42 |
# File 'lib/rucoa/range.rb', line 34 def initialize( beginning, ending, including_ending: true ) @beginning = beginning @ending = ending @including_ending = including_ending end |
Instance Attribute Details
#beginning ⇒ Rucoa::Position (readonly)
26 27 28 |
# File 'lib/rucoa/range.rb', line 26 def beginning @beginning end |
#ending ⇒ Rucoa::Position (readonly)
29 30 31 |
# File 'lib/rucoa/range.rb', line 29 def ending @ending end |
Class Method Details
.from_parser_range(range) ⇒ Rucoa::Range
8 9 10 11 12 13 |
# File 'lib/rucoa/range.rb', line 8 def from_parser_range(range) new( Position.from_parser_range_beginning(range), Position.from_parser_range_ending(range) ) end |
.from_vscode_range(hash) ⇒ Rucoa::Range
17 18 19 20 21 22 |
# File 'lib/rucoa/range.rb', line 17 def from_vscode_range(hash) new( Position.from_vscode_position(hash['start']), Position.from_vscode_position(hash['end']) ) end |
Instance Method Details
#==(other) ⇒ Boolean
46 47 48 |
# File 'lib/rucoa/range.rb', line 46 def ==(other) beginning == other.beginning && ending == other.ending end |
#contain?(range) ⇒ Boolean
75 76 77 |
# File 'lib/rucoa/range.rb', line 75 def contain?(range) include?(range.beginning) && include?(range.ending) end |
#include?(position) ⇒ Boolean
122 123 124 125 126 127 128 129 130 |
# File 'lib/rucoa/range.rb', line 122 def include?(position) return false if position.line > @ending.line return false if position.line < @beginning.line return false if position.line == @beginning.line && position.column < @beginning.column return false if position.line == @ending.line && position.column > @ending.column return false if position.line == @ending.line && position.column == @ending.column && !@including_ending true end |
#to_vscode_range ⇒ Hash
133 134 135 136 137 138 |
# File 'lib/rucoa/range.rb', line 133 def to_vscode_range { end: @ending.to_vscode_position, start: @beginning.to_vscode_position } end |