modular_tree 0.8.0 → 0.10.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: 29780afe3a4d0303217b66719daebdc62292f504a4581f19e11bac43c131a92b
4
- data.tar.gz: d712c143c16fa5957b03bd4f5a21b8e6e6a48e6ef3c09597d8f25ab3ed596a02
3
+ metadata.gz: ae3499e0ea36c7f7dd44068616ec8dd566e43be82c0e728dae86da829b085d7f
4
+ data.tar.gz: f1c35152a0b97dad0b50e85cf2061baf9bad2fed42ca4bc2bb8df3b000b81468
5
5
  SHA512:
6
- metadata.gz: b94f7f70d4777df66e1a4391ac55aa9117e23d8fc389763d3959c7b9650e1572a39bf73e6b05ce522b0371276cb8e7eba024594cc9b688ef36d1a497cfc9a87f
7
- data.tar.gz: 75ab4ec990bcf11d1f18b056eb0c1579b4fa58a7af241c7e270641bf4762085eb063428c995c390cd5baecb8df69ec6435e3609f626746a5313ed627fc607e65
6
+ metadata.gz: 71c8a99e260fe03d2453371b0afe9bc79c22234fe74a79ddf61036affd1a3129c84597006c9b5648831f1b3f469f79f26f73fd1c6263c277cee3bcea91905480
7
+ data.tar.gz: cb5feecaf6a795c91011fbafca901bb1fea9814e9b1283407b623052d9b33b801d1935d9e5594115154384ab2f49763dd5bd672dba1a3b490d800b4a9129bf3b
@@ -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
@@ -3,6 +3,7 @@ module Tree
3
3
  #
4
4
  # Pool adds a @pool class variable to the including class and all of its
5
5
  # subclasses
6
+ #
6
7
  module Pool
7
8
  include PathAlgorithms
8
9
 
@@ -14,12 +15,13 @@ module Tree
14
15
 
15
16
  def initialize(*args)
16
17
  super
18
+ !self.class.uid?(self.uid) or raise TreeError, "Duplicate UID: #{self.uid}"
17
19
  self.class.send(:[]=, self.uid, self)
18
20
  end
19
21
 
20
22
  module ClassMethods
21
- def key?(uid) = @pool.key?(uid)
22
- def keys = @pool.keys
23
+ def uid?(uid) = @pool.key?(uid)
24
+ def uids = @pool.keys
23
25
  def nodes = @pool.values
24
26
  def size = @pool.size
25
27
  def empty? = @pool.empty?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.8.0"
4
+ VERSION = "0.10.0"
5
5
  end
data/lib/modular_tree.rb CHANGED
@@ -8,6 +8,10 @@ include Constrain
8
8
  require 'forward_to'
9
9
  include ForwardTo
10
10
 
11
+ module Tree
12
+ class TreeError < RuntimeError; end
13
+ end
14
+
11
15
  require_relative "modular_tree/version"
12
16
  require_relative "modular_tree/separator"
13
17
  require_relative "modular_tree/matcher"
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.8.0
4
+ version: 0.10.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-17 00:00:00.000000000 Z
11
+ date: 2022-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constrain