Class: ConvenientService::Examples::Standard::Factorial::Services::Calculate
- Inherits:
-
Object
- Object
- ConvenientService::Examples::Standard::Factorial::Services::Calculate
- Includes:
- Service::Configs::Standard
- Defined in:
- lib/convenient_service/examples/standard/factorial/services/calculate.rb
Instance Attribute Summary collapse
-
#number ⇒ Object
readonly
Returns the value of attribute number.
-
#timeout_seconds ⇒ Object
readonly
Returns the value of attribute timeout_seconds.
Instance Method Summary collapse
-
#initialize(number:, timeout_seconds: 10) ⇒ Calculate
constructor
A new instance of Calculate.
- #result ⇒ Object
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
#number ⇒ Object (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_seconds ⇒ Object (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
#result ⇒ Object
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 |