term_utils 0.3.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -2
- data/COPYING +3 -3
- data/README.md +51 -16
- data/doc/TermUtils.html +9 -9
- data/doc/TermUtils/AP.html +48 -159
- data/doc/TermUtils/AP/Article.html +48 -46
- data/doc/TermUtils/AP/ArticleResult.html +584 -0
- data/doc/TermUtils/AP/Flag.html +294 -77
- data/doc/TermUtils/AP/NoSuchValueError.html +13 -13
- data/doc/TermUtils/AP/Parameter.html +885 -97
- data/doc/TermUtils/AP/ParameterResult.html +980 -0
- data/doc/TermUtils/{FF/Cursor/Context.html → AP/ParameterWalkerHooks.html} +59 -59
- data/doc/TermUtils/AP/ParseError.html +13 -13
- data/doc/TermUtils/AP/Parser.html +174 -142
- data/doc/TermUtils/AP/Result.html +200 -527
- data/doc/TermUtils/AP/Syntax.html +102 -392
- data/doc/TermUtils/AP/SyntaxError.html +13 -13
- data/doc/TermUtils/AP/Walker.html +686 -0
- data/doc/TermUtils/FF.html +10 -10
- data/doc/TermUtils/FF/Config.html +201 -33
- data/doc/TermUtils/FF/Context.html +585 -0
- data/doc/TermUtils/FF/Entry.html +626 -0
- data/doc/TermUtils/FF/Query.html +402 -66
- data/doc/TermUtils/PropertyTreeNode.html +302 -188
- data/doc/TermUtils/Tab.html +90 -83
- data/doc/TermUtils/Tab/Column.html +94 -92
- data/doc/TermUtils/Tab/Header.html +26 -26
- data/doc/TermUtils/Tab/Holder.html +74 -74
- data/doc/TermUtils/Tab/Printer.html +42 -42
- data/doc/TermUtils/Tab/Table.html +124 -128
- data/doc/TermUtils/Tab/TableError.html +11 -11
- data/doc/_index.html +48 -34
- data/doc/class_list.html +3 -3
- data/doc/css/style.css +2 -2
- data/doc/file.README.html +64 -31
- data/doc/file_list.html +2 -2
- data/doc/frames.html +2 -2
- data/doc/index.html +64 -31
- data/doc/js/app.js +14 -3
- data/doc/method_list.html +387 -211
- data/doc/top-level-namespace.html +6 -6
- data/lib/term_utils.rb +8 -1
- data/lib/term_utils/ap.rb +41 -30
- data/lib/term_utils/ap/article.rb +14 -8
- data/lib/term_utils/ap/flag.rb +36 -19
- data/lib/term_utils/ap/parameter.rb +87 -18
- data/lib/term_utils/ap/parser.rb +141 -115
- data/lib/term_utils/ap/result.rb +207 -160
- data/lib/term_utils/ap/syntax.rb +52 -68
- data/lib/term_utils/ff.rb +11 -2
- data/lib/term_utils/ff/config.rb +20 -8
- data/lib/term_utils/{ap/no_such_value_error.rb → ff/entry.rb} +25 -7
- data/lib/term_utils/ff/query.rb +93 -14
- data/lib/term_utils/property_tree_node.rb +47 -19
- data/lib/term_utils/tab.rb +102 -58
- data/term_utils.gemspec +4 -4
- metadata +12 -14
- data/doc/TermUtils/AP/Element.html +0 -1025
- data/doc/TermUtils/AP/Level.html +0 -638
- data/doc/TermUtils/FF/Cursor.html +0 -929
- 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,78 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
#
|
3
|
-
# Copyright (C) 2019 Thomas Baron
|
4
|
-
#
|
5
|
-
# This file is part of term_utils.
|
6
|
-
#
|
7
|
-
# term_utils is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, version 3 of the License.
|
10
|
-
#
|
11
|
-
# term_utils is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
module TermUtils
|
19
|
-
module AP
|
20
|
-
# Represents a syntax element (abstract).
|
21
|
-
class Element
|
22
|
-
# @return [Symbol]
|
23
|
-
attr_accessor :id
|
24
|
-
# @return [Integer]
|
25
|
-
attr_accessor :min_occurs
|
26
|
-
# @return [Integer]
|
27
|
-
attr_accessor :max_occurs
|
28
|
-
# @return [Array<TermUtils::AP::Flag>]
|
29
|
-
attr_accessor :flags
|
30
|
-
# For dup method.
|
31
|
-
def initialize_dup(other)
|
32
|
-
if other.flags
|
33
|
-
@flags = []
|
34
|
-
other.flags.each do |f|
|
35
|
-
@flags << f.dup
|
36
|
-
end
|
37
|
-
end
|
38
|
-
super
|
39
|
-
end
|
40
|
-
# Finalizes this one. Internal use.
|
41
|
-
# @return [nil]
|
42
|
-
def finalize!(opts = {})
|
43
|
-
raise TermUtils::AP::SyntaxError, "min_occurs must be equal or greater than 0" unless (@min_occurs.is_a? Integer) && (@min_occurs >= 0)
|
44
|
-
raise TermUtils::AP::SyntaxError, "max_occurs must be equal or greater than min_occurs" unless !occur_bounded? || (@max_occurs >= @min_occurs)
|
45
|
-
unless @id
|
46
|
-
opts[:anonymous] += 1
|
47
|
-
@id = "anonymous#{opts[:anonymous]}".intern
|
48
|
-
end
|
49
|
-
end
|
50
|
-
# Tests whether this one has mutiple occurs.
|
51
|
-
# @return [Boolean]
|
52
|
-
def multiple_occurs?
|
53
|
-
(@max_occurs == nil) || (@max_occurs == :infinity) || ((@max_occurs.is_a? Integer) && (@max_occurs > 1))
|
54
|
-
end
|
55
|
-
# Tests whether the number of occurs are fixed.
|
56
|
-
# @return [Boolean]
|
57
|
-
def occur_bounded?
|
58
|
-
(@max_occurs != nil) && (@max_occurs != :infinity) && (@max_occurs.is_a? Integer)
|
59
|
-
end
|
60
|
-
# Tests whether this one is flagged.
|
61
|
-
# @return [Boolean]
|
62
|
-
def flagged?
|
63
|
-
!@flags.empty?
|
64
|
-
end
|
65
|
-
# Adds a new Flag to this one.
|
66
|
-
# @param opts [Hash]
|
67
|
-
# @option opts [String] :label
|
68
|
-
# @option opts [Symbol] :flavor `:anchor`, `:long`, `:short`.
|
69
|
-
# @return [TermUtils::AP::Flag]
|
70
|
-
def define_flag(opts = {}, &block)
|
71
|
-
new_flag = TermUtils::AP::Flag.new(opts)
|
72
|
-
@flags << new_flag
|
73
|
-
block.call(new_flag) if block
|
74
|
-
new_flag
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
data/lib/term_utils/ap/level.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
#
|
3
|
-
# Copyright (C) 2019 Thomas Baron
|
4
|
-
#
|
5
|
-
# This file is part of term_utils.
|
6
|
-
#
|
7
|
-
# term_utils is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, version 3 of the License.
|
10
|
-
#
|
11
|
-
# term_utils is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
module TermUtils
|
19
|
-
module AP
|
20
|
-
# Represents an argument list subset. It must lead with a Flag. It has its
|
21
|
-
# own syntax.
|
22
|
-
class Level < TermUtils::AP::Element
|
23
|
-
# @return [TermUtils::AP::Syntax]
|
24
|
-
attr_accessor :syntax
|
25
|
-
# Constructs a new Level.
|
26
|
-
# @param opts [Hash]
|
27
|
-
# @option opts [Symbol] :id
|
28
|
-
# @option opts [Integer] :min_occurs Default value is `0`.
|
29
|
-
# @option opts [Integer] :max_occurs Default value is `1`.
|
30
|
-
def initialize(opts = {})
|
31
|
-
@id = opts.fetch(:id, nil)
|
32
|
-
@min_occurs = opts.fetch(:min_occurs, 0)
|
33
|
-
@max_occurs = opts.fetch(:max_occurs, 1)
|
34
|
-
@flags = []
|
35
|
-
@syntax = TermUtils::AP::Syntax.new
|
36
|
-
end
|
37
|
-
# For dup method.
|
38
|
-
def initialize_dup(other)
|
39
|
-
@syntax = other.syntax.dup
|
40
|
-
super
|
41
|
-
end
|
42
|
-
# Finalizes this one. Internal use.
|
43
|
-
# @return [nil]
|
44
|
-
def finalize!(opts = {})
|
45
|
-
super
|
46
|
-
raise TermUtils::AP::SyntaxError, "level must contain at least one flag" if @flags.empty?
|
47
|
-
@syntax.finalize!(opts)
|
48
|
-
end
|
49
|
-
# Defines the syntax.
|
50
|
-
# @return [TermUtils::AP::Syntax]
|
51
|
-
def define_syntax(&block)
|
52
|
-
block.call(@syntax) if block
|
53
|
-
@syntax
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
#
|
3
|
-
# Copyright (C) 2019 Thomas Baron
|
4
|
-
#
|
5
|
-
# This file is part of term_utils.
|
6
|
-
#
|
7
|
-
# term_utils is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, version 3 of the License.
|
10
|
-
#
|
11
|
-
# term_utils is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
module TermUtils
|
19
|
-
module AP
|
20
|
-
# Parse error.
|
21
|
-
class ParseError < StandardError
|
22
|
-
def initialize(msg)
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
#
|
3
|
-
# Copyright (C) 2019 Thomas Baron
|
4
|
-
#
|
5
|
-
# This file is part of term_utils.
|
6
|
-
#
|
7
|
-
# term_utils is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, version 3 of the License.
|
10
|
-
#
|
11
|
-
# term_utils is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
module TermUtils
|
19
|
-
module AP
|
20
|
-
# Syntax error.
|
21
|
-
class SyntaxError < StandardError
|
22
|
-
def initialize(msg)
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
data/lib/term_utils/ff/cursor.rb
DELETED
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen-string-literal: true
|
2
|
-
#
|
3
|
-
# Copyright (C) 2019 Thomas Baron
|
4
|
-
#
|
5
|
-
# This file is part of term_utils.
|
6
|
-
#
|
7
|
-
# term_utils is free software: you can redistribute it and/or modify
|
8
|
-
# it under the terms of the GNU General Public License as published by
|
9
|
-
# the Free Software Foundation, version 3 of the License.
|
10
|
-
#
|
11
|
-
# term_utils is distributed in the hope that it will be useful,
|
12
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14
|
-
# GNU General Public License for more details.
|
15
|
-
#
|
16
|
-
# You should have received a copy of the GNU General Public License
|
17
|
-
# along with term_utils. If not, see <https://www.gnu.org/licenses/>.
|
18
|
-
module TermUtils
|
19
|
-
# The ff module provides a way to find files.
|
20
|
-
module FF
|
21
|
-
# Represents a query cursor.
|
22
|
-
class Cursor
|
23
|
-
# Represents a directory context.
|
24
|
-
Context = Struct.new(:path, :components, :entries)
|
25
|
-
# @return [Integer]
|
26
|
-
attr_reader :index
|
27
|
-
# @param config [TermUtils::FF::Config]
|
28
|
-
# @param path [String]
|
29
|
-
def initialize(config, path)
|
30
|
-
@config = config
|
31
|
-
@path = path
|
32
|
-
@contexts = []
|
33
|
-
push_context(path)
|
34
|
-
@index = 0
|
35
|
-
end
|
36
|
-
# Starts the query.
|
37
|
-
# @return [TermUtils::FF::Cursor, nil]
|
38
|
-
def bootstrap
|
39
|
-
res = self
|
40
|
-
if @config.min_depth
|
41
|
-
while depth < @config.min_depth
|
42
|
-
res = following0
|
43
|
-
break unless res
|
44
|
-
end
|
45
|
-
end
|
46
|
-
res
|
47
|
-
end
|
48
|
-
# Returns the next cursor.
|
49
|
-
# @return [TermUtils::FF::Cursor, nil]
|
50
|
-
def following
|
51
|
-
res = nil
|
52
|
-
loop do
|
53
|
-
res = following0
|
54
|
-
break unless res
|
55
|
-
if @config.min_depth
|
56
|
-
next if depth < @config.min_depth
|
57
|
-
end
|
58
|
-
if @config.max_depth
|
59
|
-
next if depth > @config.max_depth
|
60
|
-
end
|
61
|
-
@index += 1
|
62
|
-
break
|
63
|
-
end
|
64
|
-
res
|
65
|
-
end
|
66
|
-
# Returns the result associated to this one.
|
67
|
-
# @return [String]
|
68
|
-
def result
|
69
|
-
@contexts.last.path
|
70
|
-
end
|
71
|
-
# @return [Integer]
|
72
|
-
def depth
|
73
|
-
@contexts.last.components.length
|
74
|
-
end
|
75
|
-
# @return [String]
|
76
|
-
def relative_path
|
77
|
-
@contexts.last.components.join("/")
|
78
|
-
end
|
79
|
-
# @return [String]
|
80
|
-
def name
|
81
|
-
@contexts.last.components[-1]
|
82
|
-
end
|
83
|
-
# Returns the path components.
|
84
|
-
# @return [Array<String>]
|
85
|
-
def components
|
86
|
-
@contexts.last.components.dup
|
87
|
-
end
|
88
|
-
private
|
89
|
-
# Returns the next cursor.
|
90
|
-
# @return [TermUtils::FF::Cursor, nil]
|
91
|
-
def following0
|
92
|
-
ctx = @contexts.last
|
93
|
-
if ctx
|
94
|
-
if ctx.entries
|
95
|
-
# Directory.
|
96
|
-
until ctx.entries.empty?
|
97
|
-
name = ctx.entries.first
|
98
|
-
break if accept_name(name)
|
99
|
-
ctx.entries.shift
|
100
|
-
end
|
101
|
-
if ctx.entries.empty?
|
102
|
-
# Walked through every entry of directory.
|
103
|
-
@contexts.pop
|
104
|
-
following0
|
105
|
-
else
|
106
|
-
# Directory entry.
|
107
|
-
new_path = StringIO.new
|
108
|
-
new_path << ctx.path
|
109
|
-
new_path << "/" if ctx.path[-1] != "/"
|
110
|
-
new_path << ctx.entries.first
|
111
|
-
new_components = ctx.components.dup
|
112
|
-
new_components << ctx.entries.first
|
113
|
-
push_context(new_path.string, new_components)
|
114
|
-
ctx.entries.shift
|
115
|
-
self
|
116
|
-
end
|
117
|
-
else
|
118
|
-
# Not directory.
|
119
|
-
@contexts.pop
|
120
|
-
following0
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
# Pushes a new context on the stask.
|
125
|
-
# @param path [String]
|
126
|
-
def push_context(path, components = [])
|
127
|
-
entries = nil
|
128
|
-
if File.directory? path
|
129
|
-
entries = Dir.entries(path)
|
130
|
-
entries.sort! if @config.sorted
|
131
|
-
end
|
132
|
-
@contexts.push(Context.new(path, components, entries))
|
133
|
-
end
|
134
|
-
# Tests whether a given name shall be accepted.
|
135
|
-
# @param name [String]
|
136
|
-
# @return [Boolean]
|
137
|
-
def accept_name(name)
|
138
|
-
if (name != ".") and (name != "..")
|
139
|
-
ret = true
|
140
|
-
@config.ignore_list.each do |i|
|
141
|
-
if i.match? name
|
142
|
-
ret = false
|
143
|
-
break
|
144
|
-
end
|
145
|
-
end
|
146
|
-
ret
|
147
|
-
else
|
148
|
-
false
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|