Skip to content

Commit

Permalink
Graph#get_neighbours fixed, Graph#directed? now return a boolean
Browse files Browse the repository at this point in the history
instead of a truthy or falsy value.
  • Loading branch information
bfontaine committed Feb 13, 2013
1 parent 7b1be78 commit a21c63e
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/graph.rb
@@ -1,3 +1,4 @@
#! /usr/bin/env ruby
# -*- coding: UTF-8 -*-

require 'yaml'
Expand Down Expand Up @@ -280,7 +281,7 @@ def not(other)
# Return true if the Graph is directed.
# @see Graph.attrs
def directed?()
self.attrs[:directed]
!!self.attrs[:directed]
end

# Clone the current graph. All nodes and edges are also cloned. A new Graph
Expand Down Expand Up @@ -407,23 +408,19 @@ def get_node(label)
# @param n [Node,String] A node with a 'label' or :label attribute, or a string
def get_neighbours(n)

label = Graph::get_label(n)
label = Graph::get_label n
neighbours = NodeArray.new []

self.edges.each do |e|

begin

l1 = e.node1
l2 = e.node2

rescue NoMethodError; next; end
l1 = e[:node1] || e['node1']
l2 = e[:node2] || e['node2']

if l2 && l1 == label

n2 = self.get_node l2

unless neighbours.include?(l2)
unless n2.nil? || neighbours.include?(n2)

neighbours.push(n2)

Expand All @@ -435,7 +432,7 @@ def get_neighbours(n)

n1 = self.get_node l1

unless neighbours.include?(n1)
unless n1.nil? || neighbours.include?(n1)

neighbours.push(n1)

Expand Down

0 comments on commit a21c63e

Please sign in to comment.