Class: CultomePlayer::Objects::Response
- Inherits:
-
Object
- Object
- CultomePlayer::Objects::Response
- Defined in:
- lib/cultome_player/objects/response.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
Instance Method Summary collapse
-
#+(response) ⇒ Response
Join two response together.
-
#failure? ⇒ Boolean
Check if the success data associated to the response is false.
-
#initialize(type, data) ⇒ Response
constructor
A new instance of Response.
-
#success? ⇒ Boolean
Check if the success data associated to the response is true.
- #to_s ⇒ Object
Constructor Details
#initialize(type, data) ⇒ Response
Returns a new instance of Response.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cultome_player/objects/response.rb', line 6 def initialize(type, data) @success = type == :success @data = data @data.each do |k,v| self.singleton_class.send(:define_method, k) do v end end end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
4 5 6 |
# File 'lib/cultome_player/objects/response.rb', line 4 def data @data end |
Instance Method Details
#+(response) ⇒ Response
Join two response together. The response type makes an OR and parameter response’s data is merged into.
35 36 37 38 39 |
# File 'lib/cultome_player/objects/response.rb', line 35 def +(response) type = success? && response.success? ? :success : :failure data = @data.merge response.data return Response.new(type, data) end |
#failure? ⇒ Boolean
Check if the success data associated to the response is false.
20 21 22 |
# File 'lib/cultome_player/objects/response.rb', line 20 def failure? !@success end |
#success? ⇒ Boolean
Check if the success data associated to the response is true.
27 28 29 |
# File 'lib/cultome_player/objects/response.rb', line 27 def success? @success end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/cultome_player/objects/response.rb', line 41 def to_s "Response #{success? ? 'successful' : 'failed'} => #{@data}" end |