modular_tree 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/modular_tree/algorithms.rb +4 -2
- data/lib/modular_tree/matcher.rb +2 -1
- data/lib/modular_tree/pool.rb +11 -3
- data/lib/modular_tree/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29780afe3a4d0303217b66719daebdc62292f504a4581f19e11bac43c131a92b
|
4
|
+
data.tar.gz: d712c143c16fa5957b03bd4f5a21b8e6e6a48e6ef3c09597d8f25ab3ed596a02
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b94f7f70d4777df66e1a4391ac55aa9117e23d8fc389763d3959c7b9650e1572a39bf73e6b05ce522b0371276cb8e7eba024594cc9b688ef36d1a497cfc9a87f
|
7
|
+
data.tar.gz: 75ab4ec990bcf11d1f18b056eb0c1579b4fa58a7af241c7e270641bf4762085eb063428c995c390cd5baecb8df69ec6435e3609f626746a5313ed627fc607e65
|
@@ -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(
|
85
|
-
matcher = Matcher.new(
|
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 }
|
data/lib/modular_tree/matcher.rb
CHANGED
@@ -27,7 +27,8 @@ module Tree
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
|
-
def initialize(
|
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
33
|
expr.nil? == block_given? or raise ArgumentError, "Expected either an argument or a block"
|
33
34
|
@expr = (expr.nil? ? block : expr)
|
data/lib/modular_tree/pool.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
module Tree
|
2
|
-
#
|
2
|
+
# A pool assumes objects has a unique identifier
|
3
|
+
#
|
4
|
+
# Pool adds a @pool class variable to the including class and all of its
|
5
|
+
# subclasses
|
3
6
|
module Pool
|
4
7
|
include PathAlgorithms
|
5
8
|
|
@@ -9,9 +12,9 @@ module Tree
|
|
9
12
|
super
|
10
13
|
end
|
11
14
|
|
12
|
-
def initialize(
|
15
|
+
def initialize(*args)
|
13
16
|
super
|
14
|
-
self.class[self.uid
|
17
|
+
self.class.send(:[]=, self.uid, self)
|
15
18
|
end
|
16
19
|
|
17
20
|
module ClassMethods
|
@@ -22,6 +25,11 @@ module Tree
|
|
22
25
|
def empty? = @pool.empty?
|
23
26
|
def [](uid) = @pool[uid]
|
24
27
|
def []=(uid, node) @pool[uid] = node end
|
28
|
+
|
29
|
+
def inherited(subclass)
|
30
|
+
subclass.instance_variable_set(:@pool, @pool)
|
31
|
+
super
|
32
|
+
end
|
25
33
|
end
|
26
34
|
end
|
27
35
|
end
|
data/lib/modular_tree/version.rb
CHANGED