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.
Files changed (70) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +16 -2
  3. data/COPYING +3 -3
  4. data/README.md +51 -16
  5. data/Rakefile +6 -0
  6. data/doc/TermUtils/AP/Article.html +57 -55
  7. data/doc/TermUtils/AP/ArticleResult.html +584 -0
  8. data/doc/TermUtils/AP/Flag.html +295 -78
  9. data/doc/TermUtils/AP/Parameter.html +891 -103
  10. data/doc/TermUtils/AP/ParameterResult.html +980 -0
  11. data/doc/TermUtils/{FF/Cursor/Context.html → AP/ParameterWalkerHooks.html} +60 -60
  12. data/doc/TermUtils/AP/ParseError.html +651 -19
  13. data/doc/TermUtils/AP/Parser.html +181 -121
  14. data/doc/TermUtils/AP/Result.html +201 -528
  15. data/doc/TermUtils/AP/Syntax.html +103 -393
  16. data/doc/TermUtils/AP/SyntaxError.html +9 -91
  17. data/doc/TermUtils/AP/Walker.html +686 -0
  18. data/doc/TermUtils/AP.html +49 -160
  19. data/doc/TermUtils/FF/Config.html +203 -35
  20. data/doc/TermUtils/FF/Context.html +585 -0
  21. data/doc/TermUtils/FF/Entry.html +626 -0
  22. data/doc/TermUtils/FF/Finder.html +850 -0
  23. data/doc/TermUtils/FF/{Cursor.html → FinderEntry.html} +473 -211
  24. data/doc/TermUtils/FF/FinderQuery.html +946 -0
  25. data/doc/TermUtils/FF/Query.html +402 -70
  26. data/doc/TermUtils/FF.html +135 -11
  27. data/doc/TermUtils/PropertyTreeNode.html +304 -190
  28. data/doc/TermUtils/Tab/Column.html +98 -96
  29. data/doc/TermUtils/Tab/Header.html +30 -30
  30. data/doc/TermUtils/Tab/Holder.html +81 -81
  31. data/doc/TermUtils/Tab/Printer.html +43 -43
  32. data/doc/TermUtils/Tab/Table.html +124 -128
  33. data/doc/TermUtils/Tab/TableError.html +7 -89
  34. data/doc/TermUtils/Tab.html +93 -86
  35. data/doc/TermUtils.html +10 -10
  36. data/doc/_index.html +62 -42
  37. data/doc/class_list.html +3 -3
  38. data/doc/css/style.css +3 -2
  39. data/doc/file.README.html +63 -26
  40. data/doc/file_list.html +2 -2
  41. data/doc/frames.html +2 -2
  42. data/doc/index.html +63 -26
  43. data/doc/js/app.js +14 -3
  44. data/doc/method_list.html +708 -236
  45. data/doc/top-level-namespace.html +7 -7
  46. data/lib/term_utils/ap/article.rb +15 -9
  47. data/lib/term_utils/ap/flag.rb +37 -20
  48. data/lib/term_utils/ap/parameter.rb +88 -19
  49. data/lib/term_utils/ap/parser.rb +143 -116
  50. data/lib/term_utils/ap/result.rb +208 -161
  51. data/lib/term_utils/ap/syntax.rb +53 -69
  52. data/lib/term_utils/ap.rb +79 -24
  53. data/lib/term_utils/ff/config.rb +22 -10
  54. data/lib/term_utils/{ap/no_such_value_error.rb → ff/entry.rb} +26 -8
  55. data/lib/term_utils/ff/finder.rb +255 -0
  56. data/lib/term_utils/ff/query.rb +94 -17
  57. data/lib/term_utils/ff.rb +12 -2
  58. data/lib/term_utils/property_tree_node.rb +47 -19
  59. data/lib/term_utils/tab.rb +106 -61
  60. data/lib/term_utils.rb +8 -1
  61. data/term_utils.gemspec +4 -4
  62. metadata +18 -17
  63. data/doc/TermUtils/AP/Element.html +0 -1025
  64. data/doc/TermUtils/AP/Level.html +0 -638
  65. data/doc/TermUtils/AP/NoSuchValueError.html +0 -217
  66. data/lib/term_utils/ap/element.rb +0 -78
  67. data/lib/term_utils/ap/level.rb +0 -57
  68. data/lib/term_utils/ap/parse_error.rb +0 -27
  69. data/lib/term_utils/ap/syntax_error.rb +0 -27
  70. data/lib/term_utils/ff/cursor.rb +0 -153
@@ -1,4 +1,6 @@
1
- # Copyright (C) 2019 Thomas Baron
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 [TermUtils::PropertyTreeNode]
22
+ # @return [PropertyTreeNode]
20
23
  attr_accessor :parent_node
21
- # @return [Array<TermUtils::PropertyTreeNode>]
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
- # Creates a new node.
28
- # @param opts [Hash<Symbol, Object>]
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 [TermUtils::PropertyTreeNode, nil]
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<Symbol,Object>] key value
71
- # @return [TermUtils::PropertyTreeNode]
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<Symbol,Object>] `:path`, `:leaf_only`
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.has_key? :path
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 or (opts[:leaf_only] and @child_nodes)
109
- if opts.has_key? :block
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 and @child_nodes
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<Symbol,Object>] `:path`, `:leaf_only`
136
- # @return [Array<TermUtils::PropertyTreeNode>]
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<Symbol,Object>] `:path`, `:leaf_only`
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<Symbol,Object>] `:path`, `:leaf_only`
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 [TermUtils::PropertyTreeNode]
191
+ # @return [PropertyTreeNode]
167
192
  def find_node(path)
168
193
  catch :found do
169
- each_node(:path => path) do |n|
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]