Class: TxAsr::ServiceResult

Inherits:
Object
  • Object
show all
Defined in:
lib/tx_asr/service_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(success: false, errors: nil, message: nil, message_type: nil, data: nil) ⇒ ServiceResult

Returns a new instance of ServiceResult.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tx_asr/service_result.rb', line 9

def initialize(success: false,
               errors: nil,
               message: nil,
               message_type: nil,
               data: nil)
  self.success = success
  self.data = data
  self.errors = errors.is_a?(Array) ? errors : [errors]
  self.message = message
  self.message_type = message_type
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



3
4
5
# File 'lib/tx_asr/service_result.rb', line 3

def data
  @data
end

#errorsObject

Returns the value of attribute errors.



3
4
5
# File 'lib/tx_asr/service_result.rb', line 3

def errors
  @errors
end

#messageObject

Returns the value of attribute message.



3
4
5
# File 'lib/tx_asr/service_result.rb', line 3

def message
  @message
end

#message_typeObject

Returns the value of attribute message_type.



3
4
5
# File 'lib/tx_asr/service_result.rb', line 3

def message_type
  @message_type
end

#successObject Also known as: success?

Returns the value of attribute success.



3
4
5
# File 'lib/tx_asr/service_result.rb', line 3

def success
  @success
end

Instance Method Details

#failure?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/tx_asr/service_result.rb', line 23

def failure?
  !success?
end

#get_message_typeObject



35
36
37
38
39
40
41
42
43
# File 'lib/tx_asr/service_result.rb', line 35

def get_message_type
  if message_type.present?
    message_type.to_sym
  elsif success?
    :notice
  else
    :error
  end
end

#on_failure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



31
32
33
# File 'lib/tx_asr/service_result.rb', line 31

def on_failure
  yield(self) if failure?
end

#on_success {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



27
28
29
# File 'lib/tx_asr/service_result.rb', line 27

def on_success
  yield(self) if success?
end