Class: ApimaticCalculator::OperationTypeEnum

Inherits:
Object
  • Object
show all
Defined in:
lib/apimatic_calculator/models/operation_type_enum.rb

Overview

Possible operators are sum, subtract, multiply, divide

Constant Summary collapse

OPERATION_TYPE_ENUM =
[
  # TODO: Write general description for SUM

  SUM = 'SUM'.freeze,

  # TODO: Write general description for SUBTRACT

  SUBTRACT = 'SUBTRACT'.freeze,

  # TODO: Write general description for MULTIPLY

  MULTIPLY = 'MULTIPLY'.freeze,

  # TODO: Write general description for DIVIDE

  DIVIDE = 'DIVIDE'.freeze
].freeze

Class Method Summary collapse

Class Method Details

.from_value(value, default_value = SUM) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/apimatic_calculator/models/operation_type_enum.rb', line 29

def self.from_value(value, default_value = SUM)
  return default_value if value.nil?

  str = value.to_s.strip

  case str.downcase
  when 'sum' then SUM
  when 'subtract' then SUBTRACT
  when 'multiply' then MULTIPLY
  when 'divide' then DIVIDE
  else
    default_value
  end
end

.validate(value) ⇒ Object



23
24
25
26
27
# File 'lib/apimatic_calculator/models/operation_type_enum.rb', line 23

def self.validate(value)
  return false if value.nil?

  OPERATION_TYPE_ENUM.include?(value)
end