modular_tree 0.9.0 → 0.11.0

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: '08649719e3acd43aaaba027428bce680e0e376a5d11192357b5fb8078795a704'
4
- data.tar.gz: '08cb0635c2ec27a4f29390bdecddbe1484f5d48dc1f180faf6b07d7122802ac1'
3
+ metadata.gz: c0947ea53f44cfdfdf8c615c26217fc7bfd86b9fae98f6c234519ace576f911d
4
+ data.tar.gz: 6dc9685845668b34db4724828f777e80d1e808557c1e8b63988f23a82fdccccf
5
5
  SHA512:
6
- metadata.gz: d2766c613470299bebff94a45aad0b386221e7a1eb159833f5d13f7c4015949687cede5cc71ed08b190f3fc7b0d24677e3e01d8ebc78f950c8fed4fadc1b7500
7
- data.tar.gz: fec9a23e683d539ba8a92510aaf4c0f0ae3c1fb64cfcac05a91f254ae49c937969a5eb83e042f5f5b4faf592b9781b24b83bffd4991ded8653f7fc8d47e34a53
6
+ metadata.gz: e18eeb61df2ec711d51501175409ce1b085dc86d01c65ae3863f9abf4c72ff2e051dfc070541652acfdc6515859a2b7e0cf9c11ea665c5d1f9146c83ad881701
7
+ data.tar.gz: b7f8dfbd482c7c64dd8f52f52d17d2ad2b4e82ee5e0604adbc790aa576ade55c0e26456df207938656ef5314fd4601809797669c11a488ba89d861e020bee905
@@ -10,14 +10,14 @@ module Tree
10
10
  include BranchesProperty
11
11
 
12
12
  # Bottom-up
13
- def ancestors
13
+ def ancestors # TODO: rename #parents
14
14
  curr = self
15
15
  a = []
16
16
  a.push curr.node while curr = curr.branch
17
17
  a
18
18
  end
19
19
 
20
- # Top-down
20
+ # Top-down # TODO: rename #ancestors
21
21
  def ancestry
22
22
  curr = self
23
23
  a = []
@@ -306,6 +306,18 @@ module Tree
306
306
 
307
307
  def path = @path ||= ancestry[1..-1]&.map(&:key)&.join(separator) || ""
308
308
  def uid() @uid ||= [parent&.uid, key].compact.join(separator) end
309
+
310
+ def search(*args, this: true, &block)
311
+ matcher = Matcher.new(*args, &block)
312
+ curr = this ? self : branch
313
+ while curr
314
+ return curr if matcher.match?(curr)
315
+ curr = curr.branch
316
+ end
317
+ end
318
+
319
+ # TODO
320
+ def lookup(key) = raise NotImplementedError
309
321
  end
310
322
 
311
323
  module DotAlgorithms
@@ -53,6 +53,12 @@ module Tree
53
53
  include ParentImplementation
54
54
  end
55
55
 
56
+ module InternalRootImplementation
57
+ include RootProperty
58
+ include InternalParentImplementation
59
+ def root = @root ||= parent&.root || self
60
+ end
61
+
56
62
  module ChildrenImplementation
57
63
  include ChildrenProperty
58
64
  include BranchesProperty
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.9.0"
4
+ VERSION = "0.11.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.9.0
4
+ version: 0.11.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-18 00:00:00.000000000 Z
11
+ date: 2022-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constrain