modular_tree 0.1.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: a3644f92428a2febb9c5eae96e14a4fb560f4661bf7b16234779dfa00f56395c
4
- data.tar.gz: 527392507133a17f32e157e26f6ab670998d157858efbc8e7b31dbc892ab0128
3
+ metadata.gz: a7ec15f5d6c64bba85a09321d1fcb7c1a22cd91fea24b1db49a2217a4dc73f08
4
+ data.tar.gz: '08cf720767c7c907e3b7d8007125fafe5a8b51abe8701d4d0a0c5d5736df5ccd'
5
5
  SHA512:
6
- metadata.gz: 339ac6d0bcdb76f76234db24f166755bbf3ab5760acf9288a790f1db047f36ad9202aad55af4304b1e72abacd1a18d106d0e046de1671821fd619df9857fdbec
7
- data.tar.gz: b2953433442cfd6eb6beba7ab2fb6940d1031b8b13bf6ee0ce7eece775895c69ed059573b931c05738627089717c5aed4423f872c9c4529ff9cfb3efd46c4f37
6
+ metadata.gz: 171988f0d2150f15a555d035fa7833e53b64784fcbbf3a4d5c3c4dc7ab352ce3aa816dee8a281c802bb236f57951112e0c1b18e451ad62b001e26f66340c3beb
7
+ data.tar.gz: 23cefa409742a9926b83fb9f1f7aecdae78b78905d7ed765c1f4fdc0044730594d1ffda4ef806c513856b75ac40ba4d788f16c13312521d333d9a73ec0be036f
@@ -49,8 +49,9 @@ module Tree
49
49
  include NodeProperty
50
50
  include BranchesProperty
51
51
 
52
- # True if the node doesn't contain any branches (#empty? for trees)
53
- def bare? = raise NotImplemented
52
+ # True if the node doesn't contain any branches (#empty? for trees).
53
+ # Default implementation in BranchesProperty
54
+ # def bare? = raise NotImplemented
54
55
 
55
56
  # The number of nodes in the tree. Note that this can be an expensive
56
57
  # operation because every node has to be visited
@@ -15,8 +15,6 @@
15
15
  #
16
16
  # Internal trees adds a parent/children relation
17
17
  #
18
- #
19
- #
20
18
  # Only internal trees have parent/child relations. External trees have only branch/branches relations
21
19
 
22
20
  module Tree
@@ -167,8 +165,17 @@ module Tree
167
165
 
168
166
  def each_child(&block) = @children.map(&block)
169
167
  def attach(child) = @children << child
168
+ def detach(arg)
169
+ key = arg.is_a?(Integer) ? arg : @children.index(arg)
170
+ child = @children.delete_at(key) or raise ArgumentError, "Can't find object"
171
+ child.send(:instance_variable_set, :@parent, nil)
172
+ child
173
+ end
170
174
 
171
- # Can be used with any array implementation
175
+ # Can be used with any array implementation. +where+ is either an Integer
176
+ # index or an object
177
+ #
178
+ # TODO: Rename #attach. #insert & #append are Enumerable operations
172
179
  def insert(where, child) = insert_append(:insert, where, child)
173
180
  def append(where, child) = insert_append(:append, where, child)
174
181
 
@@ -22,6 +22,7 @@ module Tree
22
22
 
23
23
  module BranchesProperty
24
24
  def branches = abstract_method
25
+ def bare? = branches.empty?
25
26
  def each_branch(&block) = branches.each(&block)
26
27
  end
27
28
 
@@ -34,6 +35,12 @@ module Tree
34
35
  def children = abstract_method
35
36
  def each_child(&block) = children.each(&block)
36
37
  def attach(child) = abstract_method
38
+
39
+ # :call-seq:
40
+ # detach(key)
41
+ # detach(child)
42
+ #
43
+ def detach(arg) = abstract_method
37
44
  end
38
45
 
39
46
  # TODO
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modular_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Claus Rasmussen
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-06 00:00:00.000000000 Z
11
+ date: 2022-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constrain