Class: TermUtils::AP::Result
- Inherits:
-
Object
- Object
- TermUtils::AP::Result
- Defined in:
- lib/term_utils/ap/result.rb
Overview
Represents an argument parsing Result.
Instance Attribute Summary collapse
- #parameter ⇒ Syntax readonly
- #remaining_arguments ⇒ Array<String>
- #results ⇒ Array<ParameterResult> readonly
Instance Method Summary collapse
-
#add_result(result) ⇒ Object
Adds a ParameterResult.
-
#find_parameter(id) ⇒ ParameterResult
Returns the first ParameterResult for a given parameter id.
-
#find_parameters(id) ⇒ Array<ParameterResult>
Returns all ParameterResult(s) for a given parameter id.
-
#initialize(syntax) ⇒ Result
constructor
Constructs a new Result.
-
#walk(&block) ⇒ Object
Walks through this one.
Constructor Details
#initialize(syntax) ⇒ Result
Constructs a new Result.
32 33 34 35 36 |
# File 'lib/term_utils/ap/result.rb', line 32 def initialize(syntax) @syntax = syntax @results = [] @remaining_arguments = nil end |
Instance Attribute Details
#parameter ⇒ Syntax (readonly)
24 25 26 |
# File 'lib/term_utils/ap/result.rb', line 24 def parameter @parameter end |
#remaining_arguments ⇒ Array<String>
28 29 30 |
# File 'lib/term_utils/ap/result.rb', line 28 def remaining_arguments @remaining_arguments end |
#results ⇒ Array<ParameterResult> (readonly)
26 27 28 |
# File 'lib/term_utils/ap/result.rb', line 26 def results @results end |
Instance Method Details
#add_result(result) ⇒ Object
Adds a ParameterResult.
40 41 42 |
# File 'lib/term_utils/ap/result.rb', line 40 def add_result(result) @results << result end |
#find_parameter(id) ⇒ ParameterResult
Returns the first ParameterResult for a given parameter id.
47 48 49 |
# File 'lib/term_utils/ap/result.rb', line 47 def find_parameter(id) @results.find { |r| r.param_id == id } end |
#find_parameters(id) ⇒ Array<ParameterResult>
Returns all ParameterResult(s) for a given parameter id.
54 55 56 |
# File 'lib/term_utils/ap/result.rb', line 54 def find_parameters(id) @results.find_all { |r| r.param_id == id } end |
#walk(&block) ⇒ Object
Walks through this one.
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/term_utils/ap/result.rb', line 59 def walk(&block) walker = TermUtils::AP::Walker.new block.call(walker) @results.each do |p| p.results.each do |a| walker.notify_article(a) end walker.notify_parameter(p) end walker.notify_finished(@remaining_arguments) end |