Class: ParameterList
- Inherits:
-
Object
- Object
- ParameterList
- Defined in:
- lib/model/parameter_list.rb
Instance Attribute Summary collapse
-
#end_index ⇒ Object
readonly
Returns the value of attribute end_index.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#start_index ⇒ Object
readonly
Returns the value of attribute start_index.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(tokens, start_index, end_index) ⇒ ParameterList
constructor
A new instance of ParameterList.
- #optional_parameters ⇒ Object
- #required_parameters ⇒ Object
- #sort ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(tokens, start_index, end_index) ⇒ ParameterList
Returns a new instance of ParameterList.
6 7 8 9 |
# File 'lib/model/parameter_list.rb', line 6 def initialize(tokens, start_index, end_index) @tokens, @start_index, @end_index = tokens, start_index, end_index @errors = [] end |
Instance Attribute Details
#end_index ⇒ Object (readonly)
Returns the value of attribute end_index.
4 5 6 |
# File 'lib/model/parameter_list.rb', line 4 def end_index @end_index end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
4 5 6 |
# File 'lib/model/parameter_list.rb', line 4 def errors @errors end |
#start_index ⇒ Object (readonly)
Returns the value of attribute start_index.
4 5 6 |
# File 'lib/model/parameter_list.rb', line 4 def start_index @start_index end |
Instance Method Details
#each(&block) ⇒ Object
15 16 17 18 19 |
# File 'lib/model/parameter_list.rb', line 15 def each(&block) parameters.each do |parameter| yield parameter end end |
#optional_parameters ⇒ Object
21 22 23 |
# File 'lib/model/parameter_list.rb', line 21 def optional_parameters parameters.select(&:is_optional?) end |
#required_parameters ⇒ Object
25 26 27 |
# File 'lib/model/parameter_list.rb', line 25 def required_parameters parameters.select(&:is_required?) end |
#sort ⇒ Object
11 12 13 |
# File 'lib/model/parameter_list.rb', line 11 def sort parameters.sort end |
#validate ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/model/parameter_list.rb', line 29 def validate optional_parameter_found = false parameters.each do |parameter| if parameter.is_required? && optional_parameter_found errors << { :message => "Required parameter #{parameter.name} should be specified before optional parameters", :line => parameter.line, :column => parameter.column } elsif parameter.is_optional? optional_parameter_found = true end end validate_alphabetical_order(required_parameters) validate_alphabetical_order(optional_parameters) errors.empty? end |