Class: Calpack::SimpleCalculatorController

Inherits:
BaseController show all
Defined in:
lib/calpack/controllers/simple_calculator_controller.rb

Overview

SimpleCalculatorController

Class Attribute Summary collapse

Attributes inherited from BaseController

#http_call_back, #http_client

Instance Method Summary collapse

Methods inherited from BaseController

#execute_request, #initialize, #validate_parameters, #validate_response

Constructor Details

This class inherits a constructor from Calpack::BaseController

Class Attribute Details

.instanceObject

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

Parameters:

  • operation (OperationTypeEnum)

    Required parameter: The operator to

  • x (Float)

    Required parameter: The LHS value

  • y (Float)

    Required parameter: The RHS value

Returns:

  • Float response from the API call



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(options = {})
  # Prepare query url.
  _path_url = '/{operation}'
  _path_url = APIHelper.append_url_with_template_parameters(
    _path_url,
    'operation' => options['operation']
  )
  _query_builder = Configuration.get_base_uri
  _query_builder << _path_url
  _query_builder = APIHelper.append_url_with_query_parameters(
    _query_builder,
    {
      'x' => options['x'],
      'y' => options['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

#instanceObject



15
16
17
# File 'lib/calpack/controllers/simple_calculator_controller.rb', line 15

def instance
  self.class.instance
end