Class: Voorhees::Response
- Inherits:
-
Object
- Object
- Voorhees::Response
- Defined in:
- lib/voorhees/response.rb
Instance Attribute Summary collapse
-
#json ⇒ Object
readonly
Returns the value of attribute json.
-
#klass ⇒ Object
readonly
Returns the value of attribute klass.
Instance Method Summary collapse
-
#initialize(json, klass = nil, hierarchy = nil) ⇒ Response
constructor
A new instance of Response.
- #to_objects ⇒ Object
Constructor Details
#initialize(json, klass = nil, hierarchy = nil) ⇒ Response
Returns a new instance of Response.
7 8 9 10 11 |
# File 'lib/voorhees/response.rb', line 7 def initialize(json, klass=nil, hierarchy=nil) @json = json @hierarchy = hierarchy @klass = klass end |
Instance Attribute Details
#json ⇒ Object (readonly)
Returns the value of attribute json.
5 6 7 |
# File 'lib/voorhees/response.rb', line 5 def json @json end |
#klass ⇒ Object (readonly)
Returns the value of attribute klass.
5 6 7 |
# File 'lib/voorhees/response.rb', line 5 def klass @klass end |
Instance Method Details
#to_objects ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/voorhees/response.rb', line 13 def to_objects return unless @klass raise Voorhees::NotResourceError.new unless @klass.respond_to?(:new_from_json) if @json.is_a?(Array) @json.collect do |item| @klass.new_from_json(item, @hierarchy) end else @klass.new_from_json(@json, @hierarchy) end end |