Class: TermUtils::AP::Parser
- Inherits:
-
Object
- Object
- TermUtils::AP::Parser
- Defined in:
- lib/term_utils/ap/parser.rb
Overview
Represents the argument list parser.
Class Method Summary collapse
-
.eval_article_min_occurs(articles) ⇒ Integer
Evaluates the added number of min occurs of a given array of articles.
-
.match_shortcut_flag(shortcut_flags, arg) ⇒ Array<String>?
Tests whether a given sample matches a shortcut flag.
Instance Method Summary collapse
-
#initialize ⇒ Parser
constructor
Constructs a new Parser.
-
#parse_arguments(syntax, arguments, opts = {}, &block) ⇒ Result
Parses a given list of arguments.
Constructor Details
#initialize ⇒ Parser
Constructs a new Parser.
24 25 |
# File 'lib/term_utils/ap/parser.rb', line 24 def initialize end |
Class Method Details
.eval_article_min_occurs(articles) ⇒ Integer
Evaluates the added number of min occurs of a given array of articles.
64 65 66 |
# File 'lib/term_utils/ap/parser.rb', line 64 def self.eval_article_min_occurs(articles) articles.inject(0) { |acc, a| acc + a.min_occurs } end |
.match_shortcut_flag(shortcut_flags, arg) ⇒ Array<String>?
Tests whether a given sample matches a shortcut flag.
51 52 53 54 55 56 57 58 59 |
# File 'lib/term_utils/ap/parser.rb', line 51 def self.match_shortcut_flag(shortcut_flags, arg) shortcut_flags.each do |label, flag| next unless arg.start_with? label return [flag.label, arg[label.length..-1]] end nil end |
Instance Method Details
#parse_arguments(syntax, arguments, opts = {}, &block) ⇒ Result
Parses a given list of arguments.
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/term_utils/ap/parser.rb', line 34 def parse_arguments(syntax, arguments, opts = {}, &block) syntax = syntax.dup syntax.finalize! arguments = arguments.dup res = TermUtils::AP::Result.new(syntax) catch :done do parse0(res, syntax, arguments, opts) end res.remaining_arguments = arguments res.walk(&block) if block res end |