[BioRuby-cvs] bioruby/lib/bio location.rb,0.23,0.24
Jan Aerts
aerts at dev.open-bio.org
Thu May 4 13:13:59 UTC 2006
Update of /home/repository/bioruby/bioruby/lib/bio
In directory dev.open-bio.org:/tmp/cvs-serv18988
Modified Files:
location.rb
Log Message:
Added method <=> and mixed in Comparable
Index: location.rb
===================================================================
RCS file: /home/repository/bioruby/bioruby/lib/bio/location.rb,v
retrieving revision 0.23
retrieving revision 0.24
diff -C2 -d -r0.23 -r0.24
*** location.rb 20 Apr 2006 15:58:34 -0000 0.23
--- location.rb 4 May 2006 13:13:57 -0000 0.24
***************
*** 45,49 ****
# end
class Location
!
# Parses a'location' segment, which can be 'ID:' + ('n' or 'n..m' or 'n^m'
# or "seq") with '<' or '>', and returns a Bio::Location object.
--- 45,50 ----
# end
class Location
! include Comparable
!
# Parses a'location' segment, which can be 'ID:' + ('n' or 'n..m' or 'n^m'
# or "seq") with '<' or '>', and returns a Bio::Location object.
***************
*** 130,133 ****
--- 131,166 ----
end
+ # 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
+ 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
+
end # class location
More information about the bioruby-cvs
mailing list