mementus 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26dd9d077d7ad9d1747b4071a91db233131dbba3
4
- data.tar.gz: d04e4c35b6eca0c45640cb06ba0136ab08b2453a
3
+ metadata.gz: 92652ba97da7674692fac49d6ea139aeb9c680d5
4
+ data.tar.gz: 5ea49d59abd929eb237956e2dea519e1300e94c6
5
5
  SHA512:
6
- metadata.gz: 9cf713cbafc0edd0df14e241a7c7b328948eeac489146ce96d3849fd52ffb8a75fb9f124b78beaec5828d3485a5b09099c9452bbc60a26637b67f8f30edea528
7
- data.tar.gz: 6541ecd1725179928a9dc9c6cdafe0df633222da04bff157e5b63dc3aa0b30699ce84bdcc6a14e75a0c6afef95d6b4ea9e7bfb59beca86f2954e67f9e524c13b
6
+ metadata.gz: 6bf3f09c02410fbc0070d40d0016d5161f57cecf975a660ccedebcb0d10fdebdf11e01cf63e350d1fc9d33fface9ebc81d9b64002dba5911221d4dd1a6f2b3c5
7
+ data.tar.gz: c36019eb7529244bf07b4f5c1654c87e5d55c6e675e16bd82fcdce6fccb12a328d78595170b3dc698b4a41a37967c4b437c0d19c945a0bba5e3b3d0c50cb5589
data/lib/mementus/edge.rb CHANGED
@@ -1,10 +1,31 @@
1
1
  module Mementus
2
2
  class Edge
3
- attr_reader :from, :to
3
+ attr_reader :from, :to, :label
4
4
 
5
- def initialize(from, to)
5
+ def initialize(from=nil, to=nil, label=:edge)
6
6
  @from = from
7
7
  @to = to
8
+ @label = label
9
+ end
10
+
11
+ def from=(node, label=:node)
12
+ if node.is_a?(Node)
13
+ @from = node
14
+ else
15
+ @from = Node.new(node, label)
16
+ end
17
+ end
18
+
19
+ def to=(node)
20
+ if node.is_a?(Node)
21
+ @to = node
22
+ else
23
+ @to = Node.new(node, label)
24
+ end
25
+ end
26
+
27
+ def label=(label)
28
+ @label = label
8
29
  end
9
30
 
10
31
  def nodes
@@ -25,6 +25,18 @@ module Mementus
25
25
  @index[node] ||= Set.new
26
26
  end
27
27
 
28
+ def create_edge(&block)
29
+ edge = Edge.new
30
+ yield edge
31
+ add_edge(edge)
32
+ end
33
+
34
+ def create_node(&block)
35
+ node = Node.new
36
+ yield node
37
+ add_node(node)
38
+ end
39
+
28
40
  def add_edge(edge)
29
41
  add_node(edge.from)
30
42
  add_node(edge.to)
data/lib/mementus/node.rb CHANGED
@@ -2,9 +2,17 @@ module Mementus
2
2
  class Node
3
3
  attr_reader :id, :label
4
4
 
5
- def initialize(id, label)
5
+ def initialize(id=nil, label=:node)
6
6
  @id = id
7
7
  @label = label
8
8
  end
9
+
10
+ def id=(id)
11
+ @id = id
12
+ end
13
+
14
+ def label=(label)
15
+ @label = label
16
+ end
9
17
  end
10
18
  end
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.2.2'.freeze
2
+ VERSION = '0.2.3'.freeze
3
3
  end
data/spec/graph_spec.rb CHANGED
@@ -16,6 +16,17 @@ describe Mementus::Graph do
16
16
  expect(graph.edges_count).to eq(0)
17
17
  end
18
18
 
19
+ specify '#create_node' do
20
+ graph = Mementus::Graph.new
21
+ graph.create_node do |node|
22
+ node.id = 1
23
+ node.label = :vertex
24
+ end
25
+
26
+ expect(graph.nodes_count).to eq(1)
27
+ expect(graph.edges_count).to eq(0)
28
+ end
29
+
19
30
  specify '#add_edge' do
20
31
  graph = Mementus::Graph.new
21
32
  graph.add_edge(Mementus::Edge.new(Mementus::Node.new(1, :node), Mementus::Node.new(2, :node)))
@@ -24,6 +35,18 @@ describe Mementus::Graph do
24
35
  expect(graph.edges_count).to eq(1)
25
36
  end
26
37
 
38
+ specify '#create_edge' do
39
+ graph = Mementus::Graph.new
40
+ graph.create_edge do |edge|
41
+ edge.label = :relationship
42
+ edge.from = "A"
43
+ edge.to = "B"
44
+ end
45
+
46
+ expect(graph.nodes_count).to eq(2)
47
+ expect(graph.edges_count).to eq(1)
48
+ end
49
+
27
50
  specify '#has_node?' do
28
51
  graph = Mementus::Graph.new
29
52
  node = Mementus::Node.new(1, :node)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mementus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-29 00:00:00.000000000 Z
11
+ date: 2016-04-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler