Class: Zoid::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, body) ⇒ Response

Returns a new instance of Response.



6
7
8
9
# File 'lib/zoid/response.rb', line 6

def initialize(status, body)
  @status = status
  @body = process(body)
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



4
5
6
# File 'lib/zoid/response.rb', line 4

def body
  @body
end

#statusObject (readonly)

Returns the value of attribute status.



3
4
5
# File 'lib/zoid/response.rb', line 3

def status
  @status
end

Instance Method Details

#process(value) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/zoid/response.rb', line 11

def process(value)
  case value
  when Array then process_array(value)
  when Hash  then process_hash(value)
  else value
  end
end

#process_array(array) ⇒ Object



19
20
21
22
23
# File 'lib/zoid/response.rb', line 19

def process_array(array)
  processed_array = array.map { |el| process(el) }

  Zoid::Resources.new(processed_array)
end

#process_hash(hash) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/zoid/response.rb', line 25

def process_hash(hash)
  processed_hash = hash.map do |key, value|
    [key.to_s, process(value)]
  end.to_h

  Zoid::Resource.new(processed_hash)
end