tangle 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +26 -6
- data/lib/tangle/edge.rb +3 -0
- data/lib/tangle/graph.rb +12 -3
- data/lib/tangle/mixin.rb +23 -0
- data/lib/tangle/vertex.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4456f429bc3e43dc2498e665b5ab50ceeba8ada36ed86fad33e477675237f53f
|
4
|
+
data.tar.gz: 961bfb96b98ec4bc56fc7e4feed6b36a7f5db1d5427ca636274e2799b609939a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7388845b841906216962b5b536084518a2ec2ddd645d5f13627efb860d0073a04c59afe5e088e664528e9c55a87a0deca1e6feeeee66a047b1f3ed0204b835de
|
7
|
+
data.tar.gz: 23a0299a55237a37a752ea57cbc477d70cae6a95ad80c44e004ca651a4f5faab266a9022bea668e6a73b51088811e46adee6a53a41deda278f79a8191768f6e8
|
data/README.md
CHANGED
@@ -1,8 +1,19 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/tangle.svg)](https://badge.fury.io/rb/tangle)
|
2
|
+
|
1
3
|
# Tangle
|
2
4
|
|
3
|
-
|
5
|
+
Tangle aims to untangle your graphs, by providing a set of classes for managing different types of graphs, and mixins for adding specific feature sets, like coloring or graphviz export.
|
6
|
+
|
7
|
+
**Graph types**:
|
8
|
+
* SimpleGraph
|
9
|
+
* MultiGraph
|
10
|
+
* ~~DiGraph~~
|
11
|
+
* ~~DAG~~
|
12
|
+
* ~~Tree~~
|
4
13
|
|
5
|
-
|
14
|
+
**Feature mixins**:
|
15
|
+
* Connectedness
|
16
|
+
* ~~Coloring~~
|
6
17
|
|
7
18
|
## Installation
|
8
19
|
|
@@ -22,17 +33,26 @@ Or install it yourself as:
|
|
22
33
|
|
23
34
|
## Usage
|
24
35
|
|
25
|
-
|
36
|
+
```ruby
|
37
|
+
g=Tangle::SimpleGraph.new
|
38
|
+
g.add_vertex name: 'a'
|
39
|
+
g.add_vertex name: 'b'
|
40
|
+
g.add_edge 'a', 'b'
|
41
|
+
g.connected?
|
42
|
+
=> true
|
43
|
+
g.add_edge 'b', 'b'
|
44
|
+
=> Tangle::LoopError (loops not allowed)
|
45
|
+
```
|
26
46
|
|
27
47
|
## Development
|
28
48
|
|
29
49
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
50
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
32
52
|
|
33
53
|
## Contributing
|
34
54
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/notCalle/tangle. Pull requests should be rebased to HEAD of `master` before submitting, and all commits must be signed with valid GPG key. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
56
|
|
37
57
|
## License
|
38
58
|
|
@@ -40,4 +60,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
40
60
|
|
41
61
|
## Code of Conduct
|
42
62
|
|
43
|
-
Everyone interacting in the Tangle project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
63
|
+
Everyone interacting in the Tangle project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/notCalle/tangle/blob/master/CODE_OF_CONDUCT.md).
|
data/lib/tangle/edge.rb
CHANGED
@@ -6,6 +6,7 @@ module Tangle
|
|
6
6
|
#
|
7
7
|
class Edge
|
8
8
|
extend Forwardable
|
9
|
+
include Tangle::Mixin::Initialize
|
9
10
|
|
10
11
|
# Create a new edge between vertices
|
11
12
|
#
|
@@ -18,6 +19,8 @@ module Tangle
|
|
18
19
|
@vertices = Set[vertex1, vertex2]
|
19
20
|
@graph = graph
|
20
21
|
|
22
|
+
initialize_mixins
|
23
|
+
|
21
24
|
validate_edge
|
22
25
|
end
|
23
26
|
|
data/lib/tangle/graph.rb
CHANGED
@@ -7,15 +7,15 @@ module Tangle
|
|
7
7
|
# Base class for all kinds of graphs
|
8
8
|
#
|
9
9
|
class Graph
|
10
|
+
include Tangle::Mixin::Initialize
|
10
11
|
Edge = Tangle::Edge
|
11
12
|
|
12
|
-
include Tangle::Mixin::Connectedness::Graph
|
13
|
-
|
14
13
|
# Initialize a new graph, optionally preloading it with vertices and edges
|
15
14
|
#
|
16
15
|
# Graph.new() => Graph
|
17
16
|
# Graph.new(vertices: +array_or_hash+) => Graph
|
18
17
|
# Graph.new(vertices: +array_or_hash+, edges: +array_or_hash+) => Graph
|
18
|
+
# Graph.new(mixins: [MixinModule, ...], ...) => Graph
|
19
19
|
#
|
20
20
|
# When +array_or_hash+ is a hash, it contains the objects as values and
|
21
21
|
# their names as keys. When +array_or_hash+ is an array the objects will
|
@@ -27,14 +27,21 @@ module Tangle
|
|
27
27
|
# +edges+ can contain an array of exactly two, either names of vertices
|
28
28
|
# or vertices.
|
29
29
|
#
|
30
|
+
# +mixins+ is an array of modules that can be mixed into the various
|
31
|
+
# classes that makes up a graph. Initialization of a Graph, Vertex or Edge
|
32
|
+
# looks for submodules in each mixin, with the same name and extends
|
33
|
+
# any created object. Defaults to [Tangle::Mixin::Connectedness].
|
34
|
+
#
|
30
35
|
# Any subclass of Graph should also subclass Edge to manage its unique
|
31
36
|
# constraints.
|
32
37
|
#
|
33
|
-
def initialize(vertices: nil, edges: nil
|
38
|
+
def initialize(vertices: nil, edges: nil,
|
39
|
+
mixins: [Tangle::Mixin::Connectedness])
|
34
40
|
@vertices_by_id = {}
|
35
41
|
@vertices_by_name = {}
|
36
42
|
@edges ||= []
|
37
43
|
|
44
|
+
initialize_mixins(mixins)
|
38
45
|
initialize_vertices(vertices)
|
39
46
|
initialize_edges(edges)
|
40
47
|
end
|
@@ -111,6 +118,8 @@ module Tangle
|
|
111
118
|
end
|
112
119
|
alias dup subgraph
|
113
120
|
|
121
|
+
attr_reader :mixins
|
122
|
+
|
114
123
|
protected
|
115
124
|
|
116
125
|
# Insert a prepared vertex into the graph
|
data/lib/tangle/mixin.rb
CHANGED
@@ -1 +1,24 @@
|
|
1
1
|
require 'tangle/mixin/connectedness'
|
2
|
+
|
3
|
+
module Tangle
|
4
|
+
module Mixin
|
5
|
+
#
|
6
|
+
# Mixin to initialize the dynamic mixin system
|
7
|
+
#
|
8
|
+
module Initialize
|
9
|
+
private
|
10
|
+
|
11
|
+
def initialize_mixins(mixins = nil)
|
12
|
+
klass = self.class.name[/[^:]+$/].to_sym
|
13
|
+
@mixins = mixins unless mixins.nil?
|
14
|
+
mixins ||= @graph.mixins unless @graph.nil?
|
15
|
+
|
16
|
+
return if mixins.nil?
|
17
|
+
|
18
|
+
mixins.each do |mixin|
|
19
|
+
extend(mixin.const_get(klass)) if mixin.const_defined?(klass)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/tangle/vertex.rb
CHANGED
@@ -8,7 +8,7 @@ module Tangle
|
|
8
8
|
#
|
9
9
|
class Vertex < SimpleDelegator
|
10
10
|
include PP::ObjectMixin
|
11
|
-
include Tangle::Mixin::
|
11
|
+
include Tangle::Mixin::Initialize
|
12
12
|
|
13
13
|
# Create a new vertex
|
14
14
|
#
|
@@ -29,6 +29,8 @@ module Tangle
|
|
29
29
|
@name = name
|
30
30
|
@delegate = delegate
|
31
31
|
@vertex_id = vertex_id
|
32
|
+
|
33
|
+
initialize_mixins
|
32
34
|
end
|
33
35
|
|
34
36
|
# Duplicate a vertex in a new graph, keeping all other contained attributes
|