class CultomePlayer::Objects::Response

Attributes

data[R]

Public Class Methods

new(type, data) click to toggle source
# 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

Public Instance Methods

+(response) click to toggle source

Join two response together. The response type makes an OR and parameter response's data is merged into.

@param response [Response] The response to join. @return [Response] The calculated new response.

# 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?() click to toggle source

Check if the success data associated to the response is false.

@return [Boolean] True if success data is false, False otherwise.

# File lib/cultome_player/objects/response.rb, line 20
def failure?
  !@success
end
success?() click to toggle source

Check if the success data associated to the response is true.

@return [Boolean] True if success data is true, False otherwise.

# File lib/cultome_player/objects/response.rb, line 27
def success?
  @success
end
to_s() click to toggle source
# File lib/cultome_player/objects/response.rb, line 41
def to_s
  "Response #{success? ? 'successful' : 'failed'} => #{@data}"
end