Class: Rosette::Client::HashResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/rosette/client/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ HashResponse

Returns a new instance of HashResponse.



20
21
22
# File 'lib/rosette/client/response.rb', line 20

def initialize(hash)
  @attributes = hash
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



32
33
34
35
36
# File 'lib/rosette/client/response.rb', line 32

def method_missing(method, *args, &block)
  if attributes.include?(method.to_s)
    attributes[method.to_s]
  end
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



18
19
20
# File 'lib/rosette/client/response.rb', line 18

def attributes
  @attributes
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/rosette/client/response.rb', line 24

def error?
  attributes.include?('error')
end

#respond_to?(method) ⇒ Boolean

responds to everything, returns nil for any unset attributes

Returns:

  • (Boolean)


39
40
41
# File 'lib/rosette/client/response.rb', line 39

def respond_to?(method)
  true
end

#success?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/rosette/client/response.rb', line 28

def success?
  !error?
end