rgraph 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/bin/guard ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby19
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'guard' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require 'pathname'
10
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require 'rubygems'
14
+ require 'bundler/setup'
15
+
16
+ load Gem.bin_path('guard', 'guard')
data/lib/rgraph/graph.rb CHANGED
@@ -37,6 +37,14 @@ class Graph
37
37
  @links.each(&block)
38
38
  end
39
39
 
40
+ def degrees
41
+ @nodes.map{|node| node.degree}
42
+ end
43
+
44
+ def average_degree
45
+ degrees.inject(:+) / @nodes.size.to_f
46
+ end
47
+
40
48
  private
41
49
 
42
50
  def get_node_by_id(node_id)
data/lib/rgraph/node.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  class Node
2
2
  attr_accessor :neighbours
3
+
3
4
  def initialize(arg)
4
5
  @args = arg
5
6
  @neighbours = []
6
7
  end
7
8
 
9
+ def degree
10
+ @neighbours.size
11
+ end
12
+
8
13
  def method_missing(name, *args)
9
14
  super unless args.empty?
10
15
  @args[name]
@@ -1,3 +1,3 @@
1
1
  module Rgraph
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/rgraph.gemspec CHANGED
@@ -14,7 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.license = "MIT"
15
15
 
16
16
  spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
17
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
18
  spec.require_paths = ["lib"]
20
19
 
@@ -40,5 +40,14 @@ describe Graph do
40
40
  expect { Graph.new('spec/fixtures/2005') }.to raise_exception("the file must be a .csv")
41
41
  end
42
42
  end
43
- end
44
43
 
44
+ describe "Metrics" do
45
+ subject { Graph.new('spec/fixtures/three_links.csv') }
46
+ it "returns degree of all nodes as an array" do
47
+ expect(subject.degrees).to eq([2,2,2])
48
+ end
49
+ it "calculates de average degree" do
50
+ expect(subject.average_degree).to eq(2)
51
+ end
52
+ end
53
+ end
@@ -1,10 +1,14 @@
1
1
  require_relative '../../lib/rgraph/node'
2
2
 
3
3
  describe Node do
4
- describe ".new" do
5
- subject { Node.new(name: "Lucas", node_ids: [00001, "00002", 00003], age: 20) }
6
- its(:name) { should == "Lucas" }
7
- its(:node_ids) { should == [00001, "00002", 00003] }
8
- its(:age) { should == 20 }
4
+ subject { Node.new(name: "Lucas", id: '1', age: 20) }
5
+ describe "#new" do
6
+ its(:name) { should eq "Lucas" }
7
+ its(:id) { should eq '1' }
8
+ its(:age) { should eq 20 }
9
+ end
10
+
11
+ describe "#degree" do
12
+ its(:degree) { should eq 0}
9
13
  end
10
14
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rgraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -108,6 +108,7 @@ files:
108
108
  - LICENSE
109
109
  - README.md
110
110
  - Rakefile
111
+ - bin/guard
111
112
  - lib/rgraph.rb
112
113
  - lib/rgraph/graph.rb
113
114
  - lib/rgraph/link.rb