You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+14-20Lines changed: 14 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,22 +21,22 @@ Or install it yourself as:
21
21
22
22
## Usage
23
23
24
-
Builds a tree by linking `CallableTree`node instances. The `call`methods of the nodes where the `match?`method returns a truthy value are called in a chain from the root node to the leaf node.
24
+
Builds a tree of `CallableTree`nodes. Invokes the `call`method on nodes where `match?` returns a truthy value, chaining execution from root to leaf.
25
25
26
26
-`CallableTree::Node::Internal`
27
-
-This `module` is used to define a node that can have child nodes. This node has several strategies (`seekable`, `broadcastable`, `composable`).
27
+
-Defines a node that can have child nodes. Supports several strategies (`seekable`, `broadcastable`, `composable`).
28
28
-`CallableTree::Node::External`
29
-
-This `module` is used to define a leaf node that cannot have child nodes.
29
+
-Defines a leaf node, which cannot have child nodes.
30
30
-`CallableTree::Node::Root`
31
-
-This `class` includes `CallableTree::Node::Internal`. When there is no need to customize the internal node, use this `class`.
31
+
-Includes `CallableTree::Node::Internal`. Use this class when customization of the internal node is not required.
32
32
33
33
### Basic
34
34
35
35
There are two ways to define the nodes: class style and builder style.
This strategy does not call the next sibling node if the `call` method of the current node returns a value other than `nil`. This behavior is changeable by overriding the `terminate?` method.
39
+
This strategy stops processing subsequent sibling nodes if the current node's `call` method returns a non-nil value. This behavior is changeable by overriding the `terminate?` method.
40
40
41
41
##### Class style
42
42
@@ -51,18 +51,15 @@ module Node
51
51
File.extname(input) =='.json'
52
52
end
53
53
54
-
# If there is need to convert the input values for
55
-
# child nodes, override the `call` method.
54
+
# Override `call` if you need to transform input values for child nodes.
56
55
defcall(input, **options)
57
56
File.open(input) do |file|
58
57
json = ::JSON.load(file)
59
58
super(json, **options)
60
59
end
61
60
end
62
61
63
-
# If a returned value of the `call` method is `nil`,
64
-
# but there is no need to call the sibling nodes,
65
-
# override the `terminate?` method to return `true`.
62
+
# Override `terminate?` to return `true` to stop processing sibling nodes even if `call` returns `nil`.
66
63
defterminate?(_output, *_inputs, **_options)
67
64
true
68
65
end
@@ -94,17 +91,14 @@ module Node
94
91
File.extname(input) =='.xml'
95
92
end
96
93
97
-
# If there is need to convert the input values for
98
-
# child nodes, override the `call` method.
94
+
# Override `call` if you need to transform input values for child nodes.
99
95
defcall(input, **options)
100
96
File.open(input) do |file|
101
97
super(REXML::Document.new(file), **options)
102
98
end
103
99
end
104
100
105
-
# If a returned value of the `call` method is `nil`,
106
-
# but there is no need to call the sibling nodes,
107
-
# override the `terminate?` method to return `true`.
101
+
# Override `terminate?` to return `true` to stop processing sibling nodes even if `call` returns `nil`.
108
102
defterminate?(_output, *_inputs, **_options)
109
103
true
110
104
end
@@ -131,7 +125,7 @@ module Node
131
125
end
132
126
end
133
127
134
-
# The `seekable` method call can be omitted since it is the default strategy.
128
+
# The `seekable` call can be omitted as it is the default strategy.
135
129
tree =CallableTree::Node::Root.new.seekable.append(
136
130
Node::JSON::Parser.new.seekable.append(
137
131
Node::JSON::Scraper.new(type::animals),
@@ -265,7 +259,7 @@ Run `examples/builder/internal-seekable.rb`:
265
259
266
260
#### `CallableTree::Node::Internal#broadcastable`
267
261
268
-
This strategy broadcasts to output a result of the child nodes as array. It also ignores their`terminate?` methods by default.
262
+
This strategy broadcasts input to all child nodes and returns their results as an array. It ignores child`terminate?` methods by default.
269
263
270
264
##### Class style
271
265
@@ -411,7 +405,7 @@ Run `examples/builder/internal-broadcastable.rb`:
411
405
412
406
#### `CallableTree::Node::Internal#composable`
413
407
414
-
This strategy composes the child nodes to input the output of the previous node into the next node and to output a result.
408
+
This strategy chains child nodes, passing the output of the previous node as input to the next.
415
409
It also ignores their `terminate?` methods by default.
416
410
417
411
##### Class style
@@ -560,7 +554,7 @@ Run `examples/builder/internal-composable.rb`:
560
554
561
555
#### `CallableTree::Node::External#verbosify`
562
556
563
-
If you want verbose output results, call this method.
557
+
Use this method to enable verbose output.
564
558
565
559
`examples/builder/external-verbosify.rb`:
566
560
```ruby
@@ -739,7 +733,7 @@ Run `examples/builder/logging.rb`:
739
733
740
734
#### `CallableTree::Node#identity`
741
735
742
-
If you want to customize the node identity, specify identifier.
736
+
Specify an identifier to customize the node identity.
0 commit comments