Class: Ame::Argument
- Inherits:
-
Object
- Object
- Ame::Argument
- Defined in:
- lib/ame-1.0/argument.rb
Overview
Represents an argument to a Method. It has a #name and a #description. It will be called upon to process an argument before the method this argument is associated with gets called.
Instance Attribute Summary collapse
-
#description ⇒ String
readonly
The description of the receiver.
-
#name ⇒ String
readonly
The name of the receiver.
Instance Method Summary collapse
-
#initialize(name, type, description) {|?| ... } ⇒ Argument
constructor
A new instance of Argument.
-
#process(options, processed, arguments) ⇒ Object
Invokes the optional block passed to the receiver when it was created for additional validation and parsing after optionally parsing one or more of the ARGUMENTS passed to it (see subclasses’ #parse methods for their behaviour).
-
#to_s ⇒ String
The upcasing of the #name of the receiver.
Constructor Details
#initialize(name, type, description) {|?| ... } ⇒ Argument
Returns a new instance of Argument.
17 18 19 20 |
# File 'lib/ame-1.0/argument.rb', line 17 def initialize(name, type, description, &validate) @name, @description, @validate = name, description, validate || proc{ |_, _, a| a } @type = Ame::Types[[type, String].reject(&:nil?).first] end |
Instance Attribute Details
#description ⇒ String (readonly)
Returns The description of the receiver.
26 27 28 |
# File 'lib/ame-1.0/argument.rb', line 26 def description @description end |
#name ⇒ String (readonly)
Returns The name of the receiver.
23 24 25 |
# File 'lib/ame-1.0/argument.rb', line 23 def name @name end |
Instance Method Details
#process(options, processed, arguments) ⇒ Object
Invokes the optional block passed to the receiver when it was created for additional validation and parsing after optionally parsing one or more of the ARGUMENTS passed to it (see subclasses’ #parse methods for their behaviour).
44 45 46 47 48 |
# File 'lib/ame-1.0/argument.rb', line 44 def process(, processed, arguments) @validate.call(, processed, parse(arguments)) rescue Ame::MalformedArgument, ArgumentError, TypeError => e raise Ame::MalformedArgument, '%s: %s' % [self, e] end |
#to_s ⇒ String
Returns The upcasing of the #name of the receiver.
29 30 31 |
# File 'lib/ame-1.0/argument.rb', line 29 def to_s @to_s ||= name.upcase end |