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
Methods included from Service::Configs::Standard
Methods included from Config
Constructor Details
#initialize(number:, timeout_seconds: 10) ⇒ Calculate
Returns a new instance of Calculate.
23 24 25 26 |
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 23 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.
21 22 23 |
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 21 def number @number end |
#timeout_seconds ⇒ Object (readonly)
Returns the value of attribute timeout_seconds.
21 22 23 |
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 21 def timeout_seconds @timeout_seconds end |
Instance Method Details
#result ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/convenient_service/examples/standard/factorial/services/calculate.rb', line 28 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 |