Method: Bio::Location#<=>

Defined in:
lib/bio/location.rb

#<=>(other) ⇒ Object

Check where a Bio::Location object is located compared to another Bio::Location object (mainly to facilitate the use of Comparable). A location A is upstream of location B if the start position of location A is smaller than the start position of location B. If they’re the same, the end positions are checked.


Arguments:

  • (required) _other location_: a Bio::Location object

Returns
  • 1 if self < other location

  • -1 if self > other location

  • 0 if both location are the same

  • nil if the argument is not a Bio::Location object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/bio/location.rb', line 163

def <=>(other)
  if ! other.kind_of?(Bio::Location)
    return nil
  end

  if @from.to_f < other.from.to_f
    return -1
  elsif @from.to_f > other.from.to_f
    return 1
  end

  if @to.to_f < other.to.to_f
    return -1
  elsif @to.to_f > other.to.to_f
    return 1
  end
  return 0
end