Class: Rucoa::Position
- Inherits:
-
Object
- Object
- Rucoa::Position
- Defined in:
- lib/rucoa/position.rb
Instance Attribute Summary collapse
- #column ⇒ Integer readonly
- #line ⇒ Integer readonly
Class Method Summary collapse
- .from_parser_range_beginning(range) ⇒ Rucoa::Position
- .from_parser_range_ending(range) ⇒ Rucoa::Position
- .from_vscode_position(hash) ⇒ Rucoa::Position
Instance Method Summary collapse
- #==(other) ⇒ Boolean
-
#initialize(column: 0, line: 1) ⇒ Position
constructor
A new instance of Position.
- #to_index_of(text) ⇒ Integer
- #to_range ⇒ Rucoa::Range
- #to_vscode_position ⇒ Hash
Constructor Details
#initialize(column: 0, line: 1) ⇒ Position
Returns a new instance of Position.
42 43 44 45 46 47 48 |
# File 'lib/rucoa/position.rb', line 42 def initialize( column: 0, line: 1 ) @column = column @line = line end |
Instance Attribute Details
#column ⇒ Integer (readonly)
35 36 37 |
# File 'lib/rucoa/position.rb', line 35 def column @column end |
#line ⇒ Integer (readonly)
38 39 40 |
# File 'lib/rucoa/position.rb', line 38 def line @line end |
Class Method Details
.from_parser_range_beginning(range) ⇒ Rucoa::Position
8 9 10 11 12 13 |
# File 'lib/rucoa/position.rb', line 8 def from_parser_range_beginning(range) new( column: range.column, line: range.line ) end |
.from_parser_range_ending(range) ⇒ Rucoa::Position
17 18 19 20 21 22 |
# File 'lib/rucoa/position.rb', line 17 def from_parser_range_ending(range) new( column: range.last_column, line: range.last_line ) end |
.from_vscode_position(hash) ⇒ Rucoa::Position
26 27 28 29 30 31 |
# File 'lib/rucoa/position.rb', line 26 def from_vscode_position(hash) new( column: hash['character'], line: hash['line'] + 1 ) end |
Instance Method Details
#==(other) ⇒ Boolean
52 53 54 |
# File 'lib/rucoa/position.rb', line 52 def ==(other) column == other.column && line == other.line end |
#to_index_of(text) ⇒ Integer
58 59 60 |
# File 'lib/rucoa/position.rb', line 58 def to_index_of(text) text.each_line.take(@line - 1).sum(&:length) + @column end |
#to_range ⇒ Rucoa::Range
63 64 65 |
# File 'lib/rucoa/position.rb', line 63 def to_range Range.new(self, self) end |
#to_vscode_position ⇒ Hash
68 69 70 71 72 73 |
# File 'lib/rucoa/position.rb', line 68 def to_vscode_position { 'character' => @column, 'line' => @line - 1 } end |