Class: CodeModels::SourcePosition

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(begin_point = nil, end_point = nil) ⇒ SourcePosition

Returns a new instance of SourcePosition.



100
101
102
103
# File 'lib/codemodels/position.rb', line 100

def initialize(begin_point=nil,end_point=nil)
  @begin_point = begin_point
  @end_point = end_point
end

Instance Attribute Details

#begin_pointObject

Returns the value of attribute begin_point.



94
95
96
# File 'lib/codemodels/position.rb', line 94

def begin_point
  @begin_point
end

#end_pointObject

Returns the value of attribute end_point.



94
95
96
# File 'lib/codemodels/position.rb', line 94

def end_point
  @end_point
end

Class Method Details

.from_code_indexes(code, begin_index, end_index) ⇒ Object



96
97
98
# File 'lib/codemodels/position.rb', line 96

def self.from_code_indexes(code,begin_index,end_index)
  SourcePosition.new(SourcePoint.from_code_index(code,begin_index),SourcePoint.from_code_index(code,end_index))
end

Instance Method Details

#==(other) ⇒ Object



121
122
123
# File 'lib/codemodels/position.rb', line 121

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

#begin_columnObject



143
144
145
# File 'lib/codemodels/position.rb', line 143

def begin_column
  @begin_point.column
end

#begin_column=(column) ⇒ Object



110
111
112
113
# File 'lib/codemodels/position.rb', line 110

def begin_column=(column)
  @begin_point=SourcePoint.new unless @begin_point
  @begin_point.column = column
end

#begin_lineObject



135
136
137
# File 'lib/codemodels/position.rb', line 135

def begin_line
  @begin_point.line
end

#begin_line=(line) ⇒ Object



105
106
107
108
# File 'lib/codemodels/position.rb', line 105

def begin_line=(line)
  @begin_point=SourcePoint.new unless @begin_point
  @begin_point.line = line
end

#end_columnObject



147
148
149
# File 'lib/codemodels/position.rb', line 147

def end_column
  @end_point.column
end

#end_lineObject



139
140
141
# File 'lib/codemodels/position.rb', line 139

def end_line
  @end_point.line
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


115
116
117
118
119
# File 'lib/codemodels/position.rb', line 115

def eql?(other)
  return false unless other.respond_to?(:begin_point)
  return false unless other.respond_to?(:end_point)
  other.begin_point==begin_point && other.end_point==end_point
end

#get_string(s) ⇒ Object



129
130
131
132
133
# File 'lib/codemodels/position.rb', line 129

def get_string(s)
  as = @begin_point.to_absolute_index(s)
  ae = @end_point.to_absolute_index(s)
  s[as..ae]
end

#include?(other) ⇒ Boolean

Returns:

  • (Boolean)


151
152
153
# File 'lib/codemodels/position.rb', line 151

def include?(other)
  (self.begin_point <= other.begin_point) && (self.end_point >= other.end_point)
end

#to_sObject



125
126
127
# File 'lib/codemodels/position.rb', line 125

def to_s
  "from #{@begin_point} to #{@end_point}"
end