Class: CodeModels::SourcePoint

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/codemodels/position.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line = nil, column = nil) ⇒ SourcePoint

Returns a new instance of SourcePoint.



16
17
18
19
# File 'lib/codemodels/position.rb', line 16

def initialize(line=nil,column=nil)
  self.line= line
  self.column= column
end

Instance Attribute Details

#columnObject

Returns the value of attribute column.



8
9
10
# File 'lib/codemodels/position.rb', line 8

def column
  @column
end

#lineObject

Returns the value of attribute line.



8
9
10
# File 'lib/codemodels/position.rb', line 8

def line
  @line
end

Class Method Details

.from_code_index(code, index) ⇒ Object



10
11
12
13
14
# File 'lib/codemodels/position.rb', line 10

def self.from_code_index(code,index)
  l = line(code,index)
  c = column(code,index)
  SourcePoint.new(l,c)
end

Instance Method Details

#<=>(other) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/codemodels/position.rb', line 67

def <=>(other)
  lc = self.line<=>other.line
  if lc==0
    self.column<=>other.column
  else
    lc
  end
end

#==(other) ⇒ Object



36
37
38
# File 'lib/codemodels/position.rb', line 36

def ==(other)
  self.eql?(other)
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/codemodels/position.rb', line 32

def eql?(other)
  other.line==line && other.column==column
end

#to_absolute_index(s) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/codemodels/position.rb', line 44

def to_absolute_index(s)
  index = 0
  lines = s.lines
  (@line-1).times do
    index+=lines.next.length
  end
  index+=@column
  index-=1
  index
  
  # current_line = lines.next
  # i=0
  # c=0
  # while c<@column
  #  c += current_line[i]=='\t' ? COLUMNS_FOR_TAB : 1
  #  i += 1
  # end

  # index+=c
  # index-=1
  # index    
end

#to_sObject



40
41
42
# File 'lib/codemodels/position.rb', line 40

def to_s
  "Line #{@line}, Col #{@column}"
end