Class: Bio::Relation
Overview
Bio::Relation is a simple object storing two nodes and the relation of them. The nodes and the edge (relation) can be any Ruby object. You can also compare Bio::Relation objects if the edges have Comparable property.
Instance Attribute Summary collapse
-
#edge ⇒ Object
Returns the value of attribute edge.
-
#node ⇒ Object
Returns the value of attribute node.
Instance Method Summary collapse
-
#<=>(rel) ⇒ Object
Used by the each method to compare with another Bio::Relation object.
-
#===(rel) ⇒ Object
(also: #eql?)
Compare with another Bio::Relation object whether havind same edges and same nodes.
-
#from ⇒ Object
Returns one node.
-
#hash ⇒ Object
Used by eql? method.
-
#initialize(node1, node2, edge) ⇒ Relation
constructor
Create new binary relation object consists of the two object ‘node1’ and ‘node2’ with the ‘edge’ object as the relation of them.
- #relation ⇒ Object
-
#to ⇒ Object
Returns another node.
Constructor Details
#initialize(node1, node2, edge) ⇒ Relation
Create new binary relation object consists of the two object ‘node1’ and ‘node2’ with the ‘edge’ object as the relation of them.
612 613 614 615 |
# File 'lib/bio/pathway.rb', line 612 def initialize(node1, node2, edge) @node = [node1, node2] @edge = edge end |
Instance Attribute Details
#edge ⇒ Object
Returns the value of attribute edge.
616 617 618 |
# File 'lib/bio/pathway.rb', line 616 def edge @edge end |
#node ⇒ Object
Returns the value of attribute node.
616 617 618 |
# File 'lib/bio/pathway.rb', line 616 def node @node end |
Instance Method Details
#<=>(rel) ⇒ Object
Used by the each method to compare with another Bio::Relation object. This method is only usable when the edge objects have the property of the module Comparable.
667 668 669 670 671 672 673 674 675 676 677 678 |
# File 'lib/bio/pathway.rb', line 667 def <=>(rel) unless self.edge.kind_of? Comparable raise "[Error] edges are not comparable" end if self.edge > rel.edge return 1 elsif self.edge < rel.edge return -1 elsif self.edge == rel.edge return 0 end end |
#===(rel) ⇒ Object Also known as: eql?
Compare with another Bio::Relation object whether havind same edges and same nodes. The == method compares Bio::Relation object’s id, however this case equality === method compares the internal property of the Bio::Relation object.
641 642 643 644 645 646 647 648 649 650 651 652 653 |
# File 'lib/bio/pathway.rb', line 641 def ===(rel) if self.edge == rel.edge if self.node[0] == rel.node[0] and self.node[1] == rel.node[1] return true elsif self.node[0] == rel.node[1] and self.node[1] == rel.node[0] return true else return false end else return false end end |
#from ⇒ Object
Returns one node.
619 620 621 |
# File 'lib/bio/pathway.rb', line 619 def from @node[0] end |
#hash ⇒ Object
Used by eql? method
633 634 635 |
# File 'lib/bio/pathway.rb', line 633 def hash @node.sort.push(@edge).hash end |
#relation ⇒ Object
628 629 630 |
# File 'lib/bio/pathway.rb', line 628 def relation @edge end |
#to ⇒ Object
Returns another node.
624 625 626 |
# File 'lib/bio/pathway.rb', line 624 def to @node[1] end |