Class: Calpack::SimpleCalculatorController
- Inherits:
-
BaseController
- Object
- BaseController
- Calpack::SimpleCalculatorController
- Defined in:
- lib/calpack/controllers/simple_calculator_controller.rb
Overview
SimpleCalculatorController
Class Attribute Summary collapse
-
.instance ⇒ Object
Returns the value of attribute instance.
Attributes inherited from BaseController
Instance Method Summary collapse
-
#get_calculate(options = {}) ⇒ Object
Calculates the expression using the specified operation.
- #instance ⇒ Object
Methods inherited from BaseController
#execute_request, #initialize, #validate_parameters, #validate_response
Constructor Details
This class inherits a constructor from Calpack::BaseController
Class Attribute Details
.instance ⇒ Object
Returns the value of attribute instance.
12 13 14 |
# File 'lib/calpack/controllers/simple_calculator_controller.rb', line 12 def instance @instance end |
Instance Method Details
#get_calculate(options = {}) ⇒ Object
Calculates the expression using the specified operation. apply on the variables
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/calpack/controllers/simple_calculator_controller.rb', line 25 def get_calculate( = {}) # Prepare query url. _path_url = '/{operation}' _path_url = APIHelper.append_url_with_template_parameters( _path_url, 'operation' => ['operation'] ) _query_builder = Configuration.get_base_uri _query_builder << _path_url _query_builder = APIHelper.append_url_with_query_parameters( _query_builder, { 'x' => ['x'], 'y' => ['y'] }, array_serialization: Configuration.array_serialization ) _query_url = APIHelper.clean_url _query_builder # Prepare and execute HttpRequest. _request = @http_client.get( _query_url ) _context = execute_request(_request) validate_response(_context) # Return appropriate response type. _context.response.raw_body.to_f end |
#instance ⇒ Object
15 16 17 |
# File 'lib/calpack/controllers/simple_calculator_controller.rb', line 15 def instance self.class.instance end |