mementus 0.5.2 → 0.5.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: ea57a98cf767959744e32832bb22a99d7c24bca7
4
- data.tar.gz: ab44885dd4005e78bc6638fc7bd2e82b4cc09df6
3
+ metadata.gz: 5eae3c09a4901309b458150c6a8e76dbcc345ce4
4
+ data.tar.gz: 7c29b2eafea3c245595b28c6d04b14ba80868f22
5
5
  SHA512:
6
- metadata.gz: b82452696af8da7cd562a3e664689707bf0cb065d977ee33e1741845d9e1cc73fcb44d0d08d899eeb7de9362e9294b52c97274b524327d1b680be211c11d6c28
7
- data.tar.gz: a52150325b2783d8e925010e8184329d219a6c15d0766ad3fa83e00a5b98f0776441013e527bdfd3f84804fdacaf304be9b53c148621e0adce85ad90a7a3f7b9
6
+ metadata.gz: 31115b44639e4129c9e74e0ce4b33203d8858e89a799f63d88c2e83645900c307703816e138daa89109ae0725ea254ce926d6de61c1688ab029e341324e25b58
7
+ data.tar.gz: 936165f2b0884a54b06f8092d8f5aacba3584d2fef5ac0bf1c4d1acf63da3f41bc7d6df94e4299d68882248f6771a61491a7a41643085f62beb43a08b3e604d6
@@ -22,8 +22,14 @@ module Mementus
22
22
  @structure.directed?
23
23
  end
24
24
 
25
- def n(id)
26
- Pipeline::Step.new([node(id)], Pipeline::Pipe.new(self), self)
25
+ def n(match)
26
+ if match.is_a?(Hash)
27
+ source = nodes(match)
28
+ else
29
+ source = [node(match)]
30
+ end
31
+
32
+ Pipeline::Step.new(source, Pipeline::Pipe.new(self), self)
27
33
  end
28
34
 
29
35
  def has_node?(node)
@@ -42,8 +48,8 @@ module Mementus
42
48
  @structure.edge(id)
43
49
  end
44
50
 
45
- def nodes
46
- @structure.nodes
51
+ def nodes(match=nil)
52
+ @structure.nodes(match)
47
53
  end
48
54
 
49
55
  def adjacent(id)
@@ -62,8 +62,14 @@ module Mementus
62
62
  @nodes.values.each(&block)
63
63
  end
64
64
 
65
- def nodes
66
- @nodes.values
65
+ def nodes(match=nil)
66
+ return @nodes.values unless match
67
+
68
+ @nodes.values.select do |node|
69
+ key = match.first.first
70
+ val = match.first.last
71
+ node[key] == val
72
+ end
67
73
  end
68
74
 
69
75
  def adjacent(id)
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.5.2'.freeze
2
+ VERSION = '0.5.3'.freeze
3
3
  end
@@ -6,16 +6,19 @@ describe 'pipeline api' do
6
6
  create_node do |node|
7
7
  node.id = 1
8
8
  node.label = :passage
9
+ node.props[:name] = 'one'
9
10
  end
10
11
 
11
12
  create_node do |node|
12
13
  node.id = 2
13
14
  node.label = :passage
15
+ node.props[:name] = 'two'
14
16
  end
15
17
 
16
18
  create_node do |node|
17
19
  node.id = 4
18
20
  node.label = :passage
21
+ node.props[:name] = 'three'
19
22
  end
20
23
 
21
24
  create_edge do |edge|
@@ -34,12 +37,18 @@ describe 'pipeline api' do
34
37
  end
35
38
  end
36
39
 
37
- it 'traverses from the given node' do
40
+ it 'traverses from the given node id' do
38
41
  pipeline = graph.n(1)
39
42
  expect(pipeline.id).to eq(1)
40
43
  expect(pipeline.first.id).to eq(1)
41
44
  end
42
45
 
46
+ it 'traverses from the given node match' do
47
+ pipeline = graph.n(name: 'one')
48
+ expect(pipeline.id).to eq(1)
49
+ expect(pipeline.first.id).to eq(1)
50
+ end
51
+
43
52
  it 'traverses to outgoing nodes' do
44
53
  pipeline = graph.n(1).out
45
54
  expect(pipeline.all.count).to eq(1)
@@ -81,4 +81,16 @@ describe Mementus::Structure::IncidenceList do
81
81
  end
82
82
 
83
83
  it_behaves_like "a mutable graph data structure"
84
+
85
+ describe '#nodes(match)' do
86
+ it 'matches all nodes with the given prop' do
87
+ structure.set_node(Mementus::Node.new(id: 1, props: { tag: 'item'}))
88
+ structure.set_node(Mementus::Node.new(id: 2, props: { tag: 'item'}))
89
+ structure.set_node(Mementus::Node.new(id: 3))
90
+
91
+ items = structure.nodes(tag: 'item')
92
+ expect(items.first.id).to eq(1)
93
+ expect(items.last.id).to eq(2)
94
+ end
95
+ end
84
96
  end
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.5.2
4
+ version: 0.5.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-07-27 00:00:00.000000000 Z
11
+ date: 2016-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler