class TermUtils::AP::Syntax
Represents the argument list syntax. It holds a list of parameters.
Attributes
parameters[RW]
@return [Array<Parameter>]
Public Class Methods
new()
click to toggle source
Constructs a new Syntax
.
# File lib/term_utils/ap/syntax.rb, line 27 def initialize @parameters = [] end
Public Instance Methods
define_parameter(id = nil, opts = {}, &block)
click to toggle source
Creates and adds a new Parameter
. @param id [Symbol, nil] @param opts [Hash] @option opts [Symbol] :id @option opts [Integer] :min_occurs @option opts [Integer] :max_occurs @return [Parameter]
# File lib/term_utils/ap/syntax.rb, line 54 def define_parameter(id = nil, opts = {}, &block) if id param = @parameters.find { |p| p.id == id } if param block.call(param) if block return param end opts[:id] = id end new_parameter = TermUtils::AP::Parameter.new(opts) @parameters << new_parameter block.call(new_parameter) if block new_parameter end
fetch_parameters()
click to toggle source
Fetches all flagged parameters and unflagged parameters. @return [Array]
# File lib/term_utils/ap/syntax.rb, line 72 def fetch_parameters unflagged_params = [] flagged_params = {} shortcut_flags = {} @parameters.each do |p| if p.flagged? # Flagged p.flags.each do |f| flagged_params[f.label] = p if f.long? shortcut_flags["#{f.label}="] = f else shortcut_flags[f.label] = f end end else # Unflagged unflagged_params << p end end [unflagged_params, flagged_params, shortcut_flags] end
finalize!(opts = {})
click to toggle source
Finalizes this one. Internal use. @return [nil] @raise [SyntaxError]
# File lib/term_utils/ap/syntax.rb, line 40 def finalize!(opts = {}) opts[:anonymous] = 0 unless opts.key? :anonymous opts[:flag_labels] = [] @parameters.each { |p| p.finalize!(opts) } nil end
initialize_dup(other)
click to toggle source
For dup method.
Calls superclass method
# File lib/term_utils/ap/syntax.rb, line 32 def initialize_dup(other) super(other) @parameters = other.parameters.map(&:dup) if other.parameters end