term_utils 0.3.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +16 -2
- data/COPYING +3 -3
- data/README.md +51 -16
- data/Rakefile +6 -0
- data/doc/TermUtils/AP/Article.html +57 -55
- data/doc/TermUtils/AP/ArticleResult.html +584 -0
- data/doc/TermUtils/AP/Flag.html +295 -78
- data/doc/TermUtils/AP/Parameter.html +891 -103
- data/doc/TermUtils/AP/ParameterResult.html +980 -0
- data/doc/TermUtils/{FF/Cursor/Context.html → AP/ParameterWalkerHooks.html} +60 -60
- data/doc/TermUtils/AP/ParseError.html +651 -19
- data/doc/TermUtils/AP/Parser.html +181 -121
- data/doc/TermUtils/AP/Result.html +201 -528
- data/doc/TermUtils/AP/Syntax.html +103 -393
- data/doc/TermUtils/AP/SyntaxError.html +9 -91
- data/doc/TermUtils/AP/Walker.html +686 -0
- data/doc/TermUtils/AP.html +49 -160
- data/doc/TermUtils/FF/Config.html +203 -35
- data/doc/TermUtils/FF/Context.html +585 -0
- data/doc/TermUtils/FF/Entry.html +626 -0
- data/doc/TermUtils/FF/Finder.html +850 -0
- data/doc/TermUtils/FF/{Cursor.html → FinderEntry.html} +473 -211
- data/doc/TermUtils/FF/FinderQuery.html +946 -0
- data/doc/TermUtils/FF/Query.html +402 -70
- data/doc/TermUtils/FF.html +135 -11
- data/doc/TermUtils/PropertyTreeNode.html +304 -190
- data/doc/TermUtils/Tab/Column.html +98 -96
- data/doc/TermUtils/Tab/Header.html +30 -30
- data/doc/TermUtils/Tab/Holder.html +81 -81
- data/doc/TermUtils/Tab/Printer.html +43 -43
- data/doc/TermUtils/Tab/Table.html +124 -128
- data/doc/TermUtils/Tab/TableError.html +7 -89
- data/doc/TermUtils/Tab.html +93 -86
- data/doc/TermUtils.html +10 -10
- data/doc/_index.html +62 -42
- data/doc/class_list.html +3 -3
- data/doc/css/style.css +3 -2
- data/doc/file.README.html +63 -26
- data/doc/file_list.html +2 -2
- data/doc/frames.html +2 -2
- data/doc/index.html +63 -26
- data/doc/js/app.js +14 -3
- data/doc/method_list.html +708 -236
- data/doc/top-level-namespace.html +7 -7
- data/lib/term_utils/ap/article.rb +15 -9
- data/lib/term_utils/ap/flag.rb +37 -20
- data/lib/term_utils/ap/parameter.rb +88 -19
- data/lib/term_utils/ap/parser.rb +143 -116
- data/lib/term_utils/ap/result.rb +208 -161
- data/lib/term_utils/ap/syntax.rb +53 -69
- data/lib/term_utils/ap.rb +79 -24
- data/lib/term_utils/ff/config.rb +22 -10
- data/lib/term_utils/{ap/no_such_value_error.rb → ff/entry.rb} +26 -8
- data/lib/term_utils/ff/finder.rb +255 -0
- data/lib/term_utils/ff/query.rb +94 -17
- data/lib/term_utils/ff.rb +12 -2
- data/lib/term_utils/property_tree_node.rb +47 -19
- data/lib/term_utils/tab.rb +106 -61
- data/lib/term_utils.rb +8 -1
- data/term_utils.gemspec +4 -4
- metadata +18 -17
- data/doc/TermUtils/AP/Element.html +0 -1025
- data/doc/TermUtils/AP/Level.html +0 -638
- data/doc/TermUtils/AP/NoSuchValueError.html +0 -217
- data/lib/term_utils/ap/element.rb +0 -78
- data/lib/term_utils/ap/level.rb +0 -57
- data/lib/term_utils/ap/parse_error.rb +0 -27
- data/lib/term_utils/ap/syntax_error.rb +0 -27
- data/lib/term_utils/ff/cursor.rb +0 -153
@@ -1,4 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2023 Thomas Baron
|
2
4
|
#
|
3
5
|
# This file is part of term_utils.
|
4
6
|
#
|
@@ -13,19 +15,21 @@
|
|
13
15
|
#
|
14
16
|
# You should have received a copy of the GNU General Public License
|
15
17
|
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
+
|
16
19
|
module TermUtils
|
17
20
|
# Represents a general-purpose tree node that holds a key-value pair.
|
18
21
|
class PropertyTreeNode
|
19
|
-
# @return [
|
22
|
+
# @return [PropertyTreeNode]
|
20
23
|
attr_accessor :parent_node
|
21
|
-
# @return [Array<
|
24
|
+
# @return [Array<PropertyTreeNode>]
|
22
25
|
attr_accessor :child_nodes
|
23
26
|
# @return [Object]
|
24
27
|
attr_accessor :key
|
25
28
|
# @return [Object]
|
26
29
|
attr_accessor :value
|
27
|
-
|
28
|
-
#
|
30
|
+
|
31
|
+
# Creates a new PropertyTreeNode.
|
32
|
+
# @param opts [Hash]
|
29
33
|
# option opts [Object] :key
|
30
34
|
# option opts [Object] :value
|
31
35
|
def initialize(opts = {}, &block)
|
@@ -35,6 +39,7 @@ module TermUtils
|
|
35
39
|
@value = opts.fetch(:value, nil)
|
36
40
|
block.call(self) if block
|
37
41
|
end
|
42
|
+
|
38
43
|
# For dup method.
|
39
44
|
def initialize_dup(other)
|
40
45
|
@parent_node = nil
|
@@ -48,27 +53,33 @@ module TermUtils
|
|
48
53
|
end
|
49
54
|
super
|
50
55
|
end
|
56
|
+
|
51
57
|
# Tests whether this one is the head of the tree (i.e. has no parent).
|
52
58
|
# @return [Boolean]
|
53
59
|
def head?
|
54
60
|
@parent_node == nil
|
55
61
|
end
|
62
|
+
|
56
63
|
# Tests whether this one is a leaf of the tree (i.e. has no child).
|
57
64
|
# @return [Boolean]
|
58
65
|
def leaf?
|
59
66
|
@child_nodes == nil
|
60
67
|
end
|
68
|
+
|
61
69
|
# Returns the child node identified by a given key.
|
62
70
|
# @param key [Object]
|
63
|
-
# @return [
|
71
|
+
# @return [PropertyTreeNode, nil]
|
64
72
|
def child_node(key)
|
65
73
|
if @child_nodes
|
66
74
|
@child_nodes.find { |n| n.key == key }
|
67
75
|
end
|
68
76
|
end
|
77
|
+
|
69
78
|
# Creates a new node and adds it as a child.
|
70
|
-
# @param opts [Hash
|
71
|
-
# @
|
79
|
+
# @param opts [Hash]
|
80
|
+
# @option opts [Object] :key
|
81
|
+
# @option opts [Object] :value
|
82
|
+
# @return [PropertyTreeNode]
|
72
83
|
def define_node(opts = {}, &block)
|
73
84
|
new_node = TermUtils::PropertyTreeNode.new(opts)
|
74
85
|
new_node.parent_node = self
|
@@ -77,6 +88,7 @@ module TermUtils
|
|
77
88
|
block.call(new_node) if block
|
78
89
|
new_node
|
79
90
|
end
|
91
|
+
|
80
92
|
# Builds the path of keys.
|
81
93
|
# @return [Array<Object>]
|
82
94
|
def path
|
@@ -84,12 +96,15 @@ module TermUtils
|
|
84
96
|
p << @key if @key
|
85
97
|
p
|
86
98
|
end
|
99
|
+
|
87
100
|
# Iterates over every node.
|
88
|
-
# @param opts [Hash
|
101
|
+
# @param opts [Hash]
|
102
|
+
# @option opts [Array] :path
|
103
|
+
# @option opts [Boolean] :leaf_only
|
89
104
|
# @return [nil]
|
90
105
|
def each_node(opts = {}, &block)
|
91
106
|
rpath = nil
|
92
|
-
if opts.
|
107
|
+
if opts.key? :path
|
93
108
|
rpath = opts[:path].dup
|
94
109
|
end
|
95
110
|
dive = true
|
@@ -105,15 +120,15 @@ module TermUtils
|
|
105
120
|
hide = true
|
106
121
|
end
|
107
122
|
end
|
108
|
-
unless hide
|
109
|
-
if opts.
|
123
|
+
unless hide || (opts[:leaf_only] && @child_nodes)
|
124
|
+
if opts.key? :block
|
110
125
|
opts[:block].call(self)
|
111
126
|
elsif block
|
112
127
|
block.call(self)
|
113
128
|
end
|
114
129
|
end
|
115
130
|
end # if @key
|
116
|
-
if dive
|
131
|
+
if dive && @child_nodes
|
117
132
|
ropts = opts.dup
|
118
133
|
if rpath
|
119
134
|
if rpath.empty?
|
@@ -131,9 +146,12 @@ module TermUtils
|
|
131
146
|
end
|
132
147
|
nil
|
133
148
|
end
|
149
|
+
|
134
150
|
# Collects nodes.
|
135
|
-
# @param opts [Hash
|
136
|
-
# @
|
151
|
+
# @param opts [Hash]
|
152
|
+
# @option opts [Array] :path
|
153
|
+
# @option opts [Boolean] :leaf_only
|
154
|
+
# @return [Array<PropertyTreeNode>]
|
137
155
|
def collect_nodes(opts = {})
|
138
156
|
nodes = []
|
139
157
|
each_node(opts) do |n|
|
@@ -141,8 +159,11 @@ module TermUtils
|
|
141
159
|
end
|
142
160
|
nodes
|
143
161
|
end
|
162
|
+
|
144
163
|
# Collects node paths.
|
145
|
-
# @param opts [Hash
|
164
|
+
# @param opts [Hash]
|
165
|
+
# @option opts [Array] :path
|
166
|
+
# @option opts [Boolean] :leaf_only
|
146
167
|
# @return [Array<Array<Object>>]
|
147
168
|
def collect_paths(opts = {})
|
148
169
|
paths = []
|
@@ -151,8 +172,11 @@ module TermUtils
|
|
151
172
|
end
|
152
173
|
paths
|
153
174
|
end
|
175
|
+
|
154
176
|
# Collect node values.
|
155
|
-
# @param opts [Hash
|
177
|
+
# @param opts [Hash]
|
178
|
+
# @option opts [Array] :path
|
179
|
+
# @option opts [Boolean] :leaf_only
|
156
180
|
# @return [Array<Object>]
|
157
181
|
def collect_values(opts = {})
|
158
182
|
vals = []
|
@@ -161,23 +185,26 @@ module TermUtils
|
|
161
185
|
end
|
162
186
|
vals
|
163
187
|
end
|
188
|
+
|
164
189
|
# Finds the node identified by a given path of keys.
|
165
190
|
# @param path [Array<Object>]
|
166
|
-
# @return [
|
191
|
+
# @return [PropertyTreeNode]
|
167
192
|
def find_node(path)
|
168
193
|
catch :found do
|
169
|
-
each_node(:
|
194
|
+
each_node(path: path) do |n| # rubocop:disable Lint/UnreachableLoop
|
170
195
|
throw :found, n
|
171
196
|
end
|
172
197
|
nil
|
173
198
|
end
|
174
199
|
end
|
200
|
+
|
175
201
|
# Tests whether the node identified by a given path of keys exists.
|
176
202
|
# @param path [Array<Object>]
|
177
203
|
# @return [Boolean]
|
178
204
|
def node_exists?(path)
|
179
205
|
find_node(path) != nil
|
180
206
|
end
|
207
|
+
|
181
208
|
# Evaluates the total number of nodes in the tree represented by this one.
|
182
209
|
# @param path [Array<Object>]
|
183
210
|
# @return [Integer]
|
@@ -187,6 +214,7 @@ module TermUtils
|
|
187
214
|
node.child_nodes ? node.child_nodes.length : 0
|
188
215
|
end
|
189
216
|
end
|
217
|
+
|
190
218
|
# Finds the node identified by a given path of keys and returns its value.
|
191
219
|
# @param path [Array<Object>]
|
192
220
|
# @return [Object]
|