Class: TypeProf::CodePosition

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/typeprof/code_range.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(lineno, column) ⇒ CodePosition

Returns a new instance of CodePosition.



3
4
5
6
# File 'lib/typeprof/code_range.rb', line 3

def initialize(lineno, column)
  @lineno = lineno
  @column = column
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



16
17
18
# File 'lib/typeprof/code_range.rb', line 16

def column
  @column
end

#linenoObject (readonly)

Returns the value of attribute lineno.



16
17
18
# File 'lib/typeprof/code_range.rb', line 16

def lineno
  @lineno
end

Class Method Details

.from_lsp(pos) ⇒ Object



8
9
10
# File 'lib/typeprof/code_range.rb', line 8

def self.from_lsp(pos)
  new(pos[:line] + 1, pos[:character])
end

Instance Method Details

#<=>(other) ⇒ Object



18
19
20
21
# File 'lib/typeprof/code_range.rb', line 18

def <=>(other)
  cmp = @lineno <=> other.lineno
  cmp == 0 ? @column <=> other.column : cmp
end

#==(other) ⇒ Object Also known as: eql?



25
26
27
# File 'lib/typeprof/code_range.rb', line 25

def ==(other)
  @lineno == other.lineno && @column == other.column
end

#hashObject



31
32
33
# File 'lib/typeprof/code_range.rb', line 31

def hash
  [@lineno, @column].hash
end

#leftObject



41
42
43
44
# File 'lib/typeprof/code_range.rb', line 41

def left
  raise if @column == 0
  CodePosition.new(@lineno, @column - 1)
end

#rightObject



46
47
48
# File 'lib/typeprof/code_range.rb', line 46

def right
  CodePosition.new(@lineno, @column + 1)
end

#to_lspObject



12
13
14
# File 'lib/typeprof/code_range.rb', line 12

def to_lsp
  { line: @lineno - 1, character: @column }
end

#to_sObject Also known as: inspect



35
36
37
# File 'lib/typeprof/code_range.rb', line 35

def to_s
  "(%d,%d)" % [@lineno, @column]
end