term_utils 0.1.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/AUTHORS +1 -0
  3. data/CHANGELOG.md +51 -0
  4. data/COPYING +674 -0
  5. data/README.md +99 -0
  6. data/Rakefile +55 -0
  7. data/doc/TermUtils.html +138 -0
  8. data/doc/TermUtils/AP.html +394 -0
  9. data/doc/TermUtils/AP/Article.html +993 -0
  10. data/doc/TermUtils/AP/ArticleResult.html +584 -0
  11. data/doc/TermUtils/AP/Flag.html +756 -0
  12. data/doc/TermUtils/AP/NoSuchValueError.html +217 -0
  13. data/doc/TermUtils/AP/Parameter.html +1592 -0
  14. data/doc/TermUtils/AP/ParameterResult.html +980 -0
  15. data/doc/TermUtils/AP/ParameterWalkerHooks.html +409 -0
  16. data/doc/TermUtils/AP/ParseError.html +217 -0
  17. data/doc/TermUtils/AP/Parser.html +604 -0
  18. data/doc/TermUtils/AP/Result.html +837 -0
  19. data/doc/TermUtils/AP/Syntax.html +761 -0
  20. data/doc/TermUtils/AP/SyntaxError.html +217 -0
  21. data/doc/TermUtils/AP/Walker.html +686 -0
  22. data/doc/TermUtils/FF.html +128 -0
  23. data/doc/TermUtils/FF/Config.html +774 -0
  24. data/doc/TermUtils/FF/Context.html +585 -0
  25. data/doc/TermUtils/FF/Entry.html +626 -0
  26. data/doc/TermUtils/FF/Query.html +1085 -0
  27. data/doc/TermUtils/PropertyTreeNode.html +2113 -0
  28. data/doc/TermUtils/Tab.html +1486 -0
  29. data/doc/TermUtils/Tab/Column.html +1263 -0
  30. data/doc/TermUtils/Tab/Header.html +536 -0
  31. data/doc/TermUtils/Tab/Holder.html +1210 -0
  32. data/doc/TermUtils/Tab/Printer.html +967 -0
  33. data/doc/TermUtils/Tab/Table.html +1966 -0
  34. data/doc/TermUtils/Tab/TableError.html +217 -0
  35. data/doc/_index.html +387 -0
  36. data/doc/class_list.html +51 -0
  37. data/doc/css/common.css +1 -0
  38. data/doc/css/full_list.css +58 -0
  39. data/doc/css/style.css +496 -0
  40. data/doc/file.README.html +170 -0
  41. data/doc/file_list.html +56 -0
  42. data/doc/frames.html +17 -0
  43. data/doc/index.html +170 -0
  44. data/doc/js/app.js +314 -0
  45. data/doc/js/full_list.js +216 -0
  46. data/doc/js/jquery.js +4 -0
  47. data/doc/method_list.html +1539 -0
  48. data/doc/top-level-namespace.html +110 -0
  49. data/lib/term_utils.rb +11 -0
  50. data/lib/term_utils/ap.rb +70 -0
  51. data/lib/term_utils/ap/article.rb +74 -0
  52. data/lib/term_utils/ap/flag.rb +65 -0
  53. data/lib/term_utils/ap/parameter.rb +144 -0
  54. data/lib/term_utils/ap/parser.rb +211 -0
  55. data/lib/term_utils/ap/result.rb +244 -0
  56. data/lib/term_utils/ap/syntax.rb +96 -0
  57. data/lib/term_utils/ff.rb +27 -0
  58. data/lib/term_utils/ff/config.rb +55 -0
  59. data/lib/term_utils/ff/entry.rb +45 -0
  60. data/lib/term_utils/ff/query.rb +145 -0
  61. data/lib/term_utils/property_tree_node.rb +228 -0
  62. data/lib/term_utils/tab.rb +338 -88
  63. data/term_utils.gemspec +16 -0
  64. metadata +69 -7
@@ -0,0 +1,110 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>
7
+ Top Level Namespace
8
+
9
+ &mdash; Documentation by YARD 0.9.25
10
+
11
+ </title>
12
+
13
+ <link rel="stylesheet" href="css/style.css" type="text/css" />
14
+
15
+ <link rel="stylesheet" href="css/common.css" type="text/css" />
16
+
17
+ <script type="text/javascript">
18
+ pathId = "";
19
+ relpath = '';
20
+ </script>
21
+
22
+
23
+ <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script>
24
+
25
+ <script type="text/javascript" charset="utf-8" src="js/app.js"></script>
26
+
27
+
28
+ </head>
29
+ <body>
30
+ <div class="nav_wrap">
31
+ <iframe id="nav" src="class_list.html?1"></iframe>
32
+ <div id="resizer"></div>
33
+ </div>
34
+
35
+ <div id="main" tabindex="-1">
36
+ <div id="header">
37
+ <div id="menu">
38
+
39
+ <a href="_index.html">Index</a> &raquo;
40
+
41
+
42
+ <span class="title">Top Level Namespace</span>
43
+
44
+ </div>
45
+
46
+ <div id="search">
47
+
48
+ <a class="full_list_link" id="class_list_link"
49
+ href="class_list.html">
50
+
51
+ <svg width="24" height="24">
52
+ <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
53
+ <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
54
+ <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
55
+ </svg>
56
+ </a>
57
+
58
+ </div>
59
+ <div class="clear"></div>
60
+ </div>
61
+
62
+ <div id="content"><h1>Top Level Namespace
63
+
64
+
65
+
66
+ </h1>
67
+ <div class="box_info">
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+ </div>
80
+
81
+ <h2>Defined Under Namespace</h2>
82
+ <p class="children">
83
+
84
+
85
+ <strong class="modules">Modules:</strong> <span class='object_link'><a href="TermUtils.html" title="TermUtils (module)">TermUtils</a></span>
86
+
87
+
88
+
89
+
90
+ </p>
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+ </div>
101
+
102
+ <div id="footer">
103
+ Generated on Sun Aug 2 18:35:09 2020 by
104
+ <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
105
+ 0.9.25 (ruby-2.6.5).
106
+ </div>
107
+
108
+ </div>
109
+ </body>
110
+ </html>
@@ -1,3 +1,7 @@
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 Thomas Baron
4
+ #
1
5
  # This file is part of term_utils.
2
6
  #
3
7
  # term_utils is free software: you can redistribute it and/or modify
@@ -11,4 +15,11 @@
11
15
  #
12
16
  # You should have received a copy of the GNU General Public License
13
17
  # along with term_utils. If not, see <https://www.gnu.org/licenses/>.
18
+
19
+ # Utilities for terminal application.
20
+ module TermUtils
21
+ end
22
+
23
+ require 'term_utils/ap'
24
+ require 'term_utils/ff'
14
25
  require 'term_utils/tab'
@@ -0,0 +1,70 @@
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 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
+
19
+ module TermUtils
20
+ # The Argument Parser module provides a way to parse arguments.
21
+ module AP
22
+ # NoSuchValueError.
23
+ class NoSuchValueError < StandardError
24
+ def initialize(msg)
25
+ super
26
+ end
27
+ end
28
+
29
+ # ParseError.
30
+ class ParseError < StandardError
31
+ def initialize(msg)
32
+ super
33
+ end
34
+ end
35
+
36
+ # SyntaxError.
37
+ class SyntaxError < StandardError
38
+ def initialize(msg)
39
+ super
40
+ end
41
+ end
42
+
43
+ # Creates a new Syntax.
44
+ # @return [TermUtils::AP::Syntax]
45
+ def self.create_syntax(&block)
46
+ new_syntax = TermUtils::AP::Syntax.new
47
+ block.call(new_syntax) if block
48
+ new_syntax
49
+ end
50
+
51
+ # Parses a given list of arguments.
52
+ # @param syntax [Syntax]
53
+ # @param arguments [Array<String>]
54
+ # @param opts [Hash]
55
+ # @option opts [Boolean] :strict Whether the Syntax must be considered strict.
56
+ # @return [Result]
57
+ # @raise [ParseError]
58
+ # @raise [SyntaxError]
59
+ def self.parse_arguments(syntax, arguments, opts = {}, &block)
60
+ TermUtils::AP::Parser.new.parse_arguments(syntax, arguments, opts, &block)
61
+ end
62
+ end
63
+ end
64
+
65
+ require 'term_utils/ap/article'
66
+ require 'term_utils/ap/flag'
67
+ require 'term_utils/ap/parameter'
68
+ require 'term_utils/ap/syntax'
69
+ require 'term_utils/ap/result'
70
+ require 'term_utils/ap/parser'
@@ -0,0 +1,74 @@
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 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
+
19
+ module TermUtils
20
+ module AP
21
+ # Represents a Article.
22
+ class Article
23
+ # @return [Symbol]
24
+ attr_accessor :id
25
+ # @return [Integer]
26
+ attr_accessor :min_occurs
27
+ # @return [Integer]
28
+ attr_accessor :max_occurs
29
+ # @return [Symbol] `:integer`, `:string`
30
+ attr_accessor :type
31
+ # @return [String] `%d`, `%s`.
32
+ attr_accessor :format
33
+
34
+ # Constructs a new Article.
35
+ # @param opts [Hash]
36
+ # @option opts [Symbol] :id
37
+ # @option opts [Integer] :min_occurs Default value is `1`.
38
+ # @option opts [Integer] :max_occurs Default value is `1`.
39
+ # @option opts [Symbol] :type `:integer`, `:string`.
40
+ # @option opts [Symbol] :format
41
+ def initialize(opts = {})
42
+ @id = opts.fetch(:id, nil)
43
+ @min_occurs = opts.fetch(:min_occurs, 1)
44
+ @max_occurs = opts.fetch(:max_occurs, 1)
45
+ @type = opts.fetch(:type, :string)
46
+ @format = opts.fetch(:format, '%s')
47
+ end
48
+
49
+ # Finalizes this one. Internal use.
50
+ # @return [nil]
51
+ def finalize!(opts = {})
52
+ raise TermUtils::AP::SyntaxError, 'min_occurs must be equal or greater than 0' if !@min_occurs.is_a?(Integer) || (@min_occurs < 0)
53
+ raise TermUtils::AP::SyntaxError, 'max_occurs must be equal or greater than min_occurs' if occur_bounded? && (@max_occurs < @min_occurs)
54
+
55
+ unless @id
56
+ opts[:anonymous] += 1
57
+ @id = "anonymous#{opts[:anonymous]}".intern
58
+ end
59
+ end
60
+
61
+ # Tests whether this one has mutiple occurs.
62
+ # @return [Boolean]
63
+ def multiple_occurs?
64
+ (@max_occurs == nil) || (@max_occurs.is_a?(Integer) && (@max_occurs > 1))
65
+ end
66
+
67
+ # Tests whether the number of occurs is fixed.
68
+ # @return [Boolean]
69
+ def occur_bounded?
70
+ (@max_occurs != nil) && @max_occurs.is_a?(Integer)
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,65 @@
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 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
+
19
+ module TermUtils
20
+ module AP
21
+ # Represents a Flag.
22
+ class Flag
23
+ # @return [String]
24
+ attr_reader :label
25
+ # @return [Symbol] `:long`, `:short`.
26
+ attr_reader :flavor
27
+
28
+ # Constructs a new Flag.
29
+ # @param label [String]
30
+ # @param flavor [Symbol] `:short`, `:long`.
31
+ def initialize(label, flavor)
32
+ raise TermUtils::AP::SyntaxError, 'wrong flag label' if !label.is_a?(String) || /^-+$/.match?(label) || !/^-[0-9A-Za-z_-]+$/.match?(label)
33
+ raise TermUtils::AP::SyntaxError, '' unless %i[short long].include?(flavor)
34
+
35
+ @label = label
36
+ @flavor = flavor
37
+ end
38
+
39
+ # Tests whether this one is equal to a given Flag.
40
+ def ==(other)
41
+ return false unless other.is_a?(TermUtils::AP::Flag)
42
+
43
+ @label == other.label
44
+ end
45
+
46
+ # Tests whether this one represents a long flag.
47
+ # @return [Boolean]
48
+ def long?
49
+ @flavor == :long
50
+ end
51
+
52
+ # Tests whether this one represents a short flag.
53
+ # @return [Boolean]
54
+ def short?
55
+ @flavor == :short
56
+ end
57
+
58
+ # Returns the string representation of this one.
59
+ # @return [String]
60
+ def to_s
61
+ @label
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,144 @@
1
+ # frozen-string-literal: true
2
+
3
+ # Copyright (C) 2020 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
+
19
+ module TermUtils
20
+ module AP
21
+ # Represents a Parameter.
22
+ class Parameter
23
+ # @return [Symbol]
24
+ attr_accessor :id
25
+ # @return [Integer]
26
+ attr_accessor :min_occurs
27
+ # @return [Integer]
28
+ attr_accessor :max_occurs
29
+ # @return [Array<Flag>]
30
+ attr_accessor :flags
31
+ # @return [Array<Article>]
32
+ attr_accessor :articles
33
+
34
+ # Constructs a new Parameter.
35
+ # @param opts [Hash]
36
+ # @option opts [Symbol] :id
37
+ # @option opts [Integer] :min_occurs Default value is `0`.
38
+ # @option opts [Integer] :max_occurs Default value is `1`.
39
+ def initialize(opts = {})
40
+ @id = opts.fetch(:id, nil)
41
+ @min_occurs = opts.fetch(:min_occurs, 0)
42
+ @max_occurs = opts.fetch(:max_occurs, 1)
43
+ @flags = []
44
+ @articles = []
45
+ end
46
+
47
+ # For dup method.
48
+ def initialize_dup(other)
49
+ super(other)
50
+ @flags = other.flags.map(&:dup) if other.flags
51
+ @articles = other.articles.map(&:dup) if other.articles
52
+ end
53
+
54
+ # Finalizes this one. Internal use.
55
+ # @return [nil]
56
+ # @raise [SyntaxError]
57
+ def finalize!(opts = {})
58
+ raise TermUtils::AP::SyntaxError, 'min_occurs must be equal or greater than 0' if !@min_occurs.is_a?(Integer) || (@min_occurs < 0)
59
+ raise TermUtils::AP::SyntaxError, 'max_occurs must be equal or greater than min_occurs' if occur_bounded? && (@max_occurs < @min_occurs)
60
+ raise TermUtils::AP::SyntaxError, 'empty' if @flags.empty? && @articles.empty?
61
+
62
+ unless @id
63
+ opts[:anonymous] += 1
64
+ @id = "anonymous#{opts[:anonymous]}".intern
65
+ end
66
+ @flags.each do |f|
67
+ raise TermUtils::AP::SyntaxError, 'duplicate flag label' if opts[:flag_labels].include?(f.to_s)
68
+
69
+ opts[:flag_labels] << f.to_s
70
+ end
71
+ @articles.each { |a| a.finalize!(opts) }
72
+ nil
73
+ end
74
+
75
+ # Tests whether this one has mutiple occurs.
76
+ # @return [Boolean]
77
+ def multiple_occurs?
78
+ (@max_occurs == nil) || (@max_occurs.is_a?(Integer) && (@max_occurs > 1))
79
+ end
80
+
81
+ # Tests whether the number of occurs is fixed.
82
+ # @return [Boolean]
83
+ def occur_bounded?
84
+ (@max_occurs != nil) && @max_occurs.is_a?(Integer)
85
+ end
86
+
87
+ # Tests whether this one is flagged.
88
+ # @return [Boolean]
89
+ def flagged?
90
+ !@flags.empty?
91
+ end
92
+
93
+ # Adds a new Flag to this one.
94
+ # @param label [String]
95
+ # @return [Flag]
96
+ def define_flag(label, &block)
97
+ flavor = (label.length == 2) ? :short : :long
98
+ new_flag = TermUtils::AP::Flag.new(label, flavor)
99
+ raise TermUtils::AP::SyntaxError, 'duplicate flag label' if @flags.include? new_flag
100
+
101
+ @flags << new_flag
102
+ block.call(new_flag) if block
103
+ new_flag
104
+ end
105
+
106
+ # Adds a new Article to this one.
107
+ # @param id [Symbol, nil]
108
+ # @param opts [Hash]
109
+ # @option opts [Symbol] :id
110
+ # @option opts [Integer] :min_occurs Default value is `1`.
111
+ # @option opts [Integer] :max_occurs Default value is `1`.
112
+ # @option opts [Symbol] :type `:integer`, `:string`.
113
+ # @option opts [Symbol] :format
114
+ # @return [Article]
115
+ def define_article(id = nil, opts = {}, &block)
116
+ if id
117
+ art = @articles.find { |p| p.id == id }
118
+ if art
119
+ block.call(art) if block
120
+ return art
121
+ end
122
+
123
+ opts[:id] = id
124
+ end
125
+ new_article = TermUtils::AP::Article.new(opts)
126
+ @articles << new_article
127
+ block.call(new_article) if block
128
+ new_article
129
+ end
130
+
131
+ # Fetches all flags.
132
+ # @return [Array<Flag>]
133
+ def fetch_flags
134
+ @flags.dup
135
+ end
136
+
137
+ # Fetches all articles.
138
+ # @return [Array<Article>]
139
+ def fetch_articles
140
+ @articles.collect(&:dup)
141
+ end
142
+ end
143
+ end
144
+ end