modular_tree 0.0.1 → 0.0.2
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 +12 -2
- data/lib/modular_tree/filter.rb +9 -6
- data/lib/modular_tree/implementations.rb +1 -1
- data/lib/modular_tree/version.rb +1 -1
- data/lib/modular_tree.rb +1 -0
- 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: ab7be4bf786460addacf0cabad30d5b8c0f5a0aa00900e894f933fd6f53230be
|
4
|
+
data.tar.gz: 6b9c53ba9e2edccaa298bf1696e466dccfec7262c0cb5190bd82e1cf3055d60f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 471dc9d79129be7692a3442a72ad03da18203461a7741a3815d2cb71a69c93ae68c5af787769cee2c6af14a8d787b5a1867551d681b8a88826be05227c47b2d1
|
7
|
+
data.tar.gz: 1b676cc1284e7bd48611da0cf99912262ca7f9eb4cfd8edd801e4f1ecbd5ec73941bd8cfebd069242024f71993302aa1766ef44cc38278fd0659d5791c2bec8b
|
@@ -63,11 +63,21 @@ module Tree
|
|
63
63
|
# Implementation of Enumerable#each extended with filters. The block is
|
64
64
|
# called with value, key, and parent as arguments (it may choose to
|
65
65
|
# ignore key and/or parent). Returns an enumerator of values without a block
|
66
|
-
def each(*filter, this: true, &block) = common_each(*filter, :value, :
|
66
|
+
def each(*filter, this: true, &block) = common_each(*filter, :value, :do_each_preorder, this, &block)
|
67
|
+
|
68
|
+
# Implementation of Enumerable#select extended with a single filter. As
|
69
|
+
# #each, the block is called with value, key, and parent arguments
|
70
|
+
def select(filter = nil, this: true, &block)
|
71
|
+
if block_given?
|
72
|
+
each(block, true, this: this).to_a
|
73
|
+
else
|
74
|
+
each(filter || true, true, this: this)
|
75
|
+
end
|
76
|
+
end
|
67
77
|
|
68
78
|
# Like #each but the block is called with node, key, and parent instead of
|
69
79
|
# value, key, and parent
|
70
|
-
def nodes(*filter, this: true, &block) = common_each(*filter, :node, :
|
80
|
+
def nodes(*filter, this: true, &block) = common_each(*filter, :node, :do_each_preorder, this, &block)
|
71
81
|
|
72
82
|
# Pre-order enumerator of selected nodes. Same as #each without a block
|
73
83
|
def preorder(*filter, this: true) = each(*filter, this: this)
|
data/lib/modular_tree/filter.rb
CHANGED
@@ -6,9 +6,9 @@ module Tree
|
|
6
6
|
# traverse expression decides if the child nodes should be traversed
|
7
7
|
# recursively
|
8
8
|
#
|
9
|
-
# The expressions can be a Proc, Symbol, or an array of classes. In
|
10
|
-
# addition, +select+ can
|
11
|
-
#
|
9
|
+
# The expressions can be a Proc, Symbol, Class, or an array of classes. In
|
10
|
+
# addition, +select+ can be true, and +traverse+ can be true, false, or
|
11
|
+
# nil. These values have special meanings:
|
12
12
|
#
|
13
13
|
# when +select+ is
|
14
14
|
# true Select always. This is the default
|
@@ -17,14 +17,17 @@ module Tree
|
|
17
17
|
# true Traverse always. This is the default
|
18
18
|
# false Traverse only if select didn't match
|
19
19
|
# nil Expects +select+ to return a two-tuple of booleans. Can't be
|
20
|
-
# used when +select+ is true
|
20
|
+
# used when +select+ is true. TODO: Explain
|
21
21
|
#
|
22
22
|
# If the expression is a Proc object, it will be called with the current
|
23
23
|
# node as argument. If the return value is true, the node is
|
24
24
|
# selected/traversed and skipped otherwise. If the expression is a method
|
25
25
|
# name (Symbol), the method will be called on each node with no arguments.
|
26
|
-
# It is not an error if the method doesn't exists
|
27
|
-
# selected/traversed
|
26
|
+
# It is not an error if the method doesn't exists on the a given node but
|
27
|
+
# the node is not selected/traversed
|
28
|
+
#
|
29
|
+
# If the expression is a class or an array of classes, a given node matches
|
30
|
+
# if it is an instance of one of the classes or any subclass
|
28
31
|
#
|
29
32
|
# Filters should not have side-effects because they can be used in
|
30
33
|
# enumerators that doesn't execute the filter unless the enumerator is
|
data/lib/modular_tree/version.rb
CHANGED
data/lib/modular_tree.rb
CHANGED