Class: Parameter::ParameterHandler
- Inherits:
-
RubyUtils::Parameter::BaseParameterHandler
- Object
- RubyUtils::Parameter::BaseParameterHandler
- Parameter::ParameterHandler
- Defined in:
- lib/parameter/parameter_handler.rb
Overview
class to seperate the storage of the parameter in a repository entity and checking for valid parameter combination as part of the application logic. Can raise an ArgumentError or IndexError when invalid parameter arguments or parameter combinations are provided
Instance Method Summary collapse
-
#check_constraint(v, i, symbol) ⇒ Object
private
creates a constraint error if an invalid parameter combination occurs.
-
#check_constraints_for_a ⇒ Object
private
checks constraints: !(-a + -i), !(-i + -a), !(-a + -t), !(-t + -a), !(-a + -d), !(-d + -a).
-
#check_constraints_for_c ⇒ Object
private
checks constraints: !(-c + -e), !(-e + -c), !(-c + -t), !(-t + -c).
-
#check_constraints_for_d ⇒ Object
private
checks contraints: !(-d + -i), !(-i + -d), !(-d + -t), !(-t + -d).
-
#check_constraints_for_r ⇒ Object
private
checks constraints: !(-r + -t), !(-t + -r), !(-r + -i), !(-i + -r).
-
#check_parameter_constraints ⇒ Object
private
private method to the specified parameter constraints.
-
#check_parameter_occurrence ⇒ Object
private
private method to check the occurrence of two parameters.
-
#initialize_repository(argv) ⇒ Object
method to initialize the correct repository that should be used in this handler.
-
#validate_parameters ⇒ Object
private
private method with calls of the different validations methods.
Instance Method Details
#check_constraint(v, i, symbol) ⇒ Object (private)
creates a constraint error if an invalid parameter combination occurs
94 95 96 97 98 99 |
# File 'lib/parameter/parameter_handler.rb', line 94 def check_constraint(v, i, symbol) if (@repository.parameters[symbol]) raise ArgumentError, " Error: invalid parameter combination: #{v} and #{i}" end end |
#check_constraints_for_a ⇒ Object (private)
checks constraints:
!(-a + -i), !(-i + -a),
!(-a + -t), !(-t + -a),
!(-a + -d), !(-d + -a)
57 58 59 60 61 |
# File 'lib/parameter/parameter_handler.rb', line 57 def check_constraints_for_a check_constraint('-a', '-i', :index) check_constraint('-a', '-d', :delta) check_constraint('-a', '-t', :time) end |
#check_constraints_for_c ⇒ Object (private)
checks constraints:
!(-c + -e), !(-e + -c),
!(-c + -t), !(-t + -c)
67 68 69 70 |
# File 'lib/parameter/parameter_handler.rb', line 67 def check_constraints_for_c check_constraint('-c', '-e', :extreme) if (!@repository.parameters[:section]) check_constraint('-c', '-t', :time) end |
#check_constraints_for_d ⇒ Object (private)
checks contraints:
!(-d + -i), !(-i + -d),
!(-d + -t), !(-t + -d)
76 77 78 79 |
# File 'lib/parameter/parameter_handler.rb', line 76 def check_constraints_for_d check_constraint('-d', '-i', :index) check_constraint('-d', '-t', :time) end |
#check_constraints_for_r ⇒ Object (private)
checks constraints:
!(-r + -t), !(-t + -r),
!(-r + -i), !(-i + -r)
84 85 86 87 |
# File 'lib/parameter/parameter_handler.rb', line 84 def check_constraints_for_r check_constraint('-r', '-t', :time) check_constraint('-r', '-i', :index) end |
#check_parameter_constraints ⇒ Object (private)
private method to the specified parameter constraints
35 36 37 38 39 40 41 42 43 |
# File 'lib/parameter/parameter_handler.rb', line 35 def check_parameter_constraints check_constraints_for_a if (@repository.parameters[:all]) check_constraints_for_c if (@repository.parameters[:coord]) check_constraints_for_d if (@repository.parameters[:delta]) check_constraints_for_r if (@repository.parameters[:range]) # check mandatory file parameter check_mandatory_parameter(:file) end |
#check_parameter_occurrence ⇒ Object (private)
private method to check the occurrence of two parameters
46 47 48 49 50 |
# File 'lib/parameter/parameter_handler.rb', line 46 def check_parameter_occurrence if (@repository.parameters[:section] && !@repository.parameters[:help]) check_occurrence('-s', '-c', :coord) end end |
#initialize_repository(argv) ⇒ Object
method to initialize the correct repository that should be used in this handler
17 18 19 |
# File 'lib/parameter/parameter_handler.rb', line 17 def initialize_repository(argv) @repository = ParameterRepository.new(argv) end |
#validate_parameters ⇒ Object (private)
private method with calls of the different validations methods
24 25 26 27 28 29 30 31 32 |
# File 'lib/parameter/parameter_handler.rb', line 24 def validate_parameters check_for_valid_filepath if (@repository.parameters[:file]) check_number_of_parameters(:coord, 2) check_number_of_parameters(:delta, 2) check_number_of_parameters(:time, 2) check_number_of_parameters(:range, 2) check_number_of_parameters(:section, 2) end |