Class: TermUtils::AP::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/term_utils/ap/result.rb

Overview

Represents an argument parsing Result.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(syntax) ⇒ Result

Constructs a new Result.

Parameters:



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

#parameterSyntax (readonly)

Returns:



24
25
26
# File 'lib/term_utils/ap/result.rb', line 24

def parameter
  @parameter
end

#remaining_argumentsArray<String>

Returns:

  • (Array<String>)


28
29
30
# File 'lib/term_utils/ap/result.rb', line 28

def remaining_arguments
  @remaining_arguments
end

#resultsArray<ParameterResult> (readonly)

Returns:



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.

Parameters:



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.

Parameters:

  • id (Symbol)

Returns:



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.

Parameters:

  • id (Symbol)

Returns:



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