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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 68b534152678b108e1d5ad38d3947ac056fc1218a01f7bab10f73dcb0f6868bc
4
- data.tar.gz: 9ebf86f0191780d2b49f69f8b3e2cf8a0b57ac9117ff7d5dff57a0bfd52fa346
3
+ metadata.gz: 4456f429bc3e43dc2498e665b5ab50ceeba8ada36ed86fad33e477675237f53f
4
+ data.tar.gz: 961bfb96b98ec4bc56fc7e4feed6b36a7f5db1d5427ca636274e2799b609939a
5
5
  SHA512:
6
- metadata.gz: cdb0d5204e4e6fc4de0d1a54f92fb73d3808322b7478de49fb9c571998fb18c49f400cbff042c4bd38218d2c966a9e7ca5ac697b7120d26bd46193e157bca4a6
7
- data.tar.gz: 2eacf5cfb13389a359566563d6d72fae9ee86d1d373030b8677f6674d38cdec2663b5d5dfbb66a75aac6018ea41539691c75fcbee93deb4cefe48bde7cf7b591
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tangle`. To experiment with that code, run `bin/console` for an interactive prompt.
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
- TODO: Delete this and the text above, and describe your gem
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
- TODO: Write usage instructions here
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`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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/[USERNAME]/tangle. 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.
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/[USERNAME]/tangle/blob/master/CODE_OF_CONDUCT.md).
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).
@@ -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
 
@@ -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
@@ -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
@@ -8,7 +8,7 @@ module Tangle
8
8
  #
9
9
  class Vertex < SimpleDelegator
10
10
  include PP::ObjectMixin
11
- include Tangle::Mixin::Connectedness::Vertex
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tangle
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calle Englund