Class: ConvenientService::Examples::Standard::Factorial::Services::Calculate

Inherits:
Object
  • Object
show all
Includes:
Service::Configs::Standard
Defined in:
lib/convenient_service/examples/standard/factorial/services/calculate.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(number:, timeout_seconds: 10) ⇒ Calculate

Returns a new instance of Calculate.



18
19
20
21
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 18

def initialize(number:, timeout_seconds: 10)
  @number = number
  @timeout_seconds = timeout_seconds
end

Instance Attribute Details

#numberObject (readonly)

Returns the value of attribute number.



16
17
18
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 16

def number
  @number
end

#timeout_secondsObject (readonly)

Returns the value of attribute timeout_seconds.



16
17
18
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 16

def timeout_seconds
  @timeout_seconds
end

Instance Method Details

#resultObject



23
24
25
26
27
28
29
30
31
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 23

def result
  return error("is `nil`") if number.nil?
  return error("is NOT an integer") unless number.instance_of?(::Integer)
  return error("is lower than `0`") if number < 0

  return error("Timeout (`#{timeout_seconds}` seconds) is exceeded for `#{number}`") if factorial.timeout?

  success(factorial: factorial.value)
end