modular_tree 0.5.0 → 0.7.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: '0900ab1e0482487fcb6b63c28fccb0d7dc7f71e5ce54230f3ee551ff67f0dfb5'
4
- data.tar.gz: bf6b30a19df1fa8211b355bf06392dbefad2950a2a52bd494dad99605f392669
3
+ metadata.gz: 70c50cd21f7eb027dcb0560bb164268c929860f61e2912dfbb1a0fd1576f5869
4
+ data.tar.gz: 120a0efd4e6dda689412e3618267645e4252ba6b24c8949203162a2c0b979fdf
5
5
  SHA512:
6
- metadata.gz: 52d2ea9f3c82c6e7578f50b51804c223d267b1757f0709776addf39752e1034a57b14354f6877236d12017f2368300c5f3064537a3592f2fcf72bd69e2f991de
7
- data.tar.gz: ad298843f7e45b03654ef53b96c507cf51ee0219c01abc4f30619a9396b17c9e775b64fb10b4fa9d3a9bbce0232f7235e2de2e283632a1cba38690634b9c909b
6
+ metadata.gz: 62af79315ea3ec5c46e47b9e8cd1807b0f6dd33ee914d1a12b37cf8e0006bd2a2be6381e033e1883da88884bcae2e4ffb5a4e66b4d3ca3026d09721ba4e5c9d0
7
+ data.tar.gz: 12a75c54c67fd37c920ec4c663cd6199038c713c86d79f14a11143432f79ab1621115e0af7a1266dfecb8a56e5c073d8bf5e30b485e17af21accf840c78f7b4c
@@ -80,9 +80,11 @@ module Tree
80
80
  # Filter children. Doesn't recurse. If a block is given, it should return
81
81
  # truish to select a child node
82
82
  #
83
+ # The match expression can also be a list of classes (instead of an array of classes)
84
+ #
83
85
  # TODO: Maybe make #children an Array extended with filtering
84
- def choose(match_expr = nil, &block)
85
- matcher = Matcher.new(match_expr, &block)
86
+ def choose(*args, &block)
87
+ matcher = Matcher.new(*args, &block)
86
88
  if block_given?
87
89
  a = []
88
90
  each_branch { |branch, key| a << branch if matcher.match? branch }
@@ -27,9 +27,10 @@ module Tree
27
27
  end
28
28
  end
29
29
 
30
- def initialize(expr = nil, &block)
30
+ def initialize(*args, &block)
31
+ expr = args.size == 1 ? args.first : args
31
32
  constrain expr, Proc, Symbol, Class, [Class], true, false, nil
32
- expr.nil? == block_given? or raise ArgumentError
33
+ expr.nil? == block_given? or raise ArgumentError, "Expected either an argument or a block"
33
34
  @expr = (expr.nil? ? block : expr)
34
35
  end
35
36
 
@@ -18,6 +18,8 @@ module Tree
18
18
  def key?(uid) = @pool.key?(uid)
19
19
  def keys = @pool.keys
20
20
  def nodes = @pool.values
21
+ def size = @pool.size
22
+ def empty? = @pool.empty?
21
23
  def [](uid) = @pool[uid]
22
24
  def []=(uid, node) @pool[uid] = node end
23
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Tree
4
- VERSION = "0.5.0"
4
+ VERSION = "0.7.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.5.0
4
+ version: 0.7.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-15 00:00:00.000000000 Z
11
+ date: 2022-12-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: constrain