mementus 0.5.4 → 0.5.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1a81084582c056ebd9ffc11f636e3633bbdb35a
4
- data.tar.gz: 51a351b8653e9c56d3d1b6cf80035c90ab181b58
3
+ metadata.gz: 72100572fe7d20e4135b4663a269a8d2bd73cc80
4
+ data.tar.gz: 0b337f00327f6090a323f91eb5450f4f80c692c6
5
5
  SHA512:
6
- metadata.gz: 54473a495eaed1580a4d90020154707bb45476162952e83ce2eda7f23a99e7ac39f7f4a0da3dc6a90eac17762c61df4f8b78adb70fbecd61dfcff17faea3f27a
7
- data.tar.gz: 0e8d597eff99b132875226ba868ce25e498d00c6011839e9836808f5da76e0df617e596743ad086a8ecf6a057e0e405daa30547f546dc8cb9b39108e234b38f3
6
+ metadata.gz: 271a2b5486669883f8ea63c1cd615418195628481dcc1e939511e218bed016032a03b66cc19d03bb2bb856d603223c5a70fc43d45f0f2e7a9e22eeb76f10b063
7
+ data.tar.gz: b641562129543c2db046c924ad6fbcabc3cc033bdebe3f127c819ddec5af18ab8d907921f59ac505b20fb66456067b6c65ba67d54aa6125e7914ff31cd6b2a02
@@ -23,7 +23,7 @@ module Mementus
23
23
  end
24
24
 
25
25
  def n(match)
26
- if match.is_a?(Hash)
26
+ if match.is_a?(Hash) || match.is_a?(Symbol)
27
27
  source = nodes(match)
28
28
  else
29
29
  source = [node(match)]
@@ -65,20 +65,32 @@ module Mementus
65
65
  def nodes(match=nil)
66
66
  return @nodes.values unless match
67
67
 
68
- @nodes.values.select do |node|
69
- key = match.first.first
70
- val = match.first.last
71
- node[key] == val
68
+ if match.is_a?(Hash)
69
+ @nodes.values.select do |node|
70
+ key = match.first.first
71
+ val = match.first.last
72
+ node[key] == val
73
+ end
74
+ elsif match.is_a?(Symbol)
75
+ @nodes.values.select do |node|
76
+ node.label == match
77
+ end
72
78
  end
73
79
  end
74
80
 
75
81
  def edges(match=nil)
76
82
  return @edges.values unless match
77
83
 
78
- @edges.values.select do |edge|
79
- key = match.first.first
80
- val = match.first.last
81
- edge[key] == val
84
+ if match.is_a?(Hash)
85
+ @edges.values.select do |edge|
86
+ key = match.first.first
87
+ val = match.first.last
88
+ edge[key] == val
89
+ end
90
+ elsif match.is_a?(Symbol)
91
+ @edges.values.select do |edge|
92
+ edge.label == match
93
+ end
82
94
  end
83
95
  end
84
96
 
@@ -1,3 +1,3 @@
1
1
  module Mementus
2
- VERSION = '0.5.4'.freeze
2
+ VERSION = '0.5.5'.freeze
3
3
  end
data/lib/mementus.rb CHANGED
@@ -5,7 +5,6 @@ require 'mementus/structure/incidence_list'
5
5
  require 'mementus/node'
6
6
  require 'mementus/edge'
7
7
  require 'mementus/node_proxy'
8
- require 'mementus/processor'
9
8
  require 'mementus/pipeline/pipe'
10
9
  require 'mementus/pipeline/filter'
11
10
  require 'mementus/pipeline/transform'
@@ -49,6 +49,12 @@ describe 'pipeline api' do
49
49
  expect(pipeline.first.id).to eq(1)
50
50
  end
51
51
 
52
+ it 'traverses from the given label match' do
53
+ pipeline = graph.n(:passage)
54
+ expect(pipeline.id).to eq([1, 2, 4])
55
+ expect(pipeline.first.id).to eq(1)
56
+ end
57
+
52
58
  it 'traverses to outgoing nodes' do
53
59
  pipeline = graph.n(1).out
54
60
  expect(pipeline.all.count).to eq(1)
@@ -88,9 +88,21 @@ describe Mementus::Structure::IncidenceList do
88
88
  structure.set_node(Mementus::Node.new(id: 2, props: { tag: 'point'}))
89
89
  structure.set_node(Mementus::Node.new(id: 3))
90
90
 
91
- matched = structure.nodes(tag: 'point')
92
- expect(matched.first.id).to eq(1)
93
- expect(matched.last.id).to eq(2)
91
+ structure.nodes(tag: 'point').tap do |matched|
92
+ expect(matched.first.id).to eq(1)
93
+ expect(matched.last.id).to eq(2)
94
+ end
95
+ end
96
+
97
+ it 'matches all nodes with the given label' do
98
+ structure.set_node(Mementus::Node.new(id: 1, label: :point))
99
+ structure.set_node(Mementus::Node.new(id: 2, label: :point))
100
+ structure.set_node(Mementus::Node.new(id: 3))
101
+
102
+ structure.nodes(:point).tap do |matched|
103
+ expect(matched.first.id).to eq(1)
104
+ expect(matched.last.id).to eq(2)
105
+ end
94
106
  end
95
107
  end
96
108
 
@@ -99,22 +111,35 @@ describe Mementus::Structure::IncidenceList do
99
111
  edge = Mementus::Edge.new(id: 3, from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2))
100
112
  structure.set_edge(edge)
101
113
 
102
- matched = structure.edges
103
- expect(matched.first.id).to eq(edge.id)
104
- expect(matched.first.from.id).to eq(edge.from.id)
105
- expect(matched.first.to.id).to eq(edge.to.id)
114
+ structure.edges.tap do |matched|
115
+ expect(matched.first.id).to eq(edge.id)
116
+ expect(matched.first.from.id).to eq(edge.from.id)
117
+ expect(matched.first.to.id).to eq(edge.to.id)
118
+ end
106
119
  end
107
120
  end
108
121
 
109
122
  describe '#edges(match)' do
110
- it 'lists all edges with the given prop' do
123
+ it 'matches all edges with the given prop' do
111
124
  edge = Mementus::Edge.new(props: { tag: 'link' }, from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2))
112
125
  structure.set_edge(edge)
113
126
 
114
- matched = structure.edges(tag: 'link')
115
- expect(matched.first.id).to eq(edge.id)
116
- expect(matched.first.from.id).to eq(edge.from.id)
117
- expect(matched.first.to.id).to eq(edge.to.id)
127
+ structure.edges(tag: 'link').tap do |matched|
128
+ expect(matched.first.id).to eq(edge.id)
129
+ expect(matched.first.from.id).to eq(edge.from.id)
130
+ expect(matched.first.to.id).to eq(edge.to.id)
131
+ end
132
+ end
133
+
134
+ it 'matches all edges with the given label' do
135
+ edge = Mementus::Edge.new(label: :link, from: Mementus::Node.new(id: 1), to: Mementus::Node.new(id: 2))
136
+ structure.set_edge(edge)
137
+
138
+ structure.edges(:link).tap do |matched|
139
+ expect(matched.first.id).to eq(edge.id)
140
+ expect(matched.first.from.id).to eq(edge.from.id)
141
+ expect(matched.first.to.id).to eq(edge.to.id)
142
+ end
118
143
  end
119
144
  end
120
145
  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.4
4
+ version: 0.5.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - maetl
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-07 00:00:00.000000000 Z
11
+ date: 2016-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -89,7 +89,6 @@ files:
89
89
  - lib/mementus/pipes/node.rb
90
90
  - lib/mementus/pipes/outgoing.rb
91
91
  - lib/mementus/pipes/outgoing_edges.rb
92
- - lib/mementus/processor.rb
93
92
  - lib/mementus/structure/adjacency_list.rb
94
93
  - lib/mementus/structure/incidence_list.rb
95
94
  - lib/mementus/version.rb
@@ -1,58 +0,0 @@
1
- module Mementus
2
- class Processor
3
- def initialize(graph, start_pipe)
4
- @graph = graph
5
- @pipeline = [start_pipe]
6
- end
7
-
8
- def append_next(pipe)
9
- @pipeline << pipe
10
- end
11
-
12
- def process
13
- output = nil
14
- @pipeline.each do |pipe|
15
- output = pipe.process(@graph, output)
16
- end
17
- output
18
- end
19
-
20
- def id
21
- process.id
22
- end
23
-
24
- def one
25
- output = process
26
-
27
- if output.respond_to?(:each)
28
- output.first
29
- else
30
- output
31
- end
32
- end
33
-
34
- def all
35
- process.to_a
36
- end
37
-
38
- def out
39
- append_next(Pipes::Outgoing.new)
40
- self
41
- end
42
-
43
- def out_e
44
- append_next(Pipes::OutgoingEdges.new)
45
- self
46
- end
47
-
48
- def in
49
- append_next(Pipes::Incoming.new)
50
- self
51
- end
52
-
53
- def in_e
54
- append_next(Pipes::IncomingEdges.new)
55
- self
56
- end
57
- end
58
- end