Class: Restulicious::Parser::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/restulicious/parser/default.rb

Instance Method Summary collapse

Constructor Details

#initialize(klazz, collection_key, body) ⇒ Default

Returns a new instance of Default.



5
6
7
8
9
# File 'lib/restulicious/parser/default.rb', line 5

def initialize(klazz, collection_key, body)
  @klazz          = klazz
  @collection_key = collection_key
  @body           = body
end

Instance Method Details

#resultObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/restulicious/parser/default.rb', line 11

def result
  if collection?
    if @collection_key == "none"
      collection = []
      hashified_body.each do |object_attributes|
        collection << @klazz.from_api(object_attributes.symbolize_keys!)
      end
      collection
    else
      Restulicious::Collection.from_parser(@klazz, @collection_key, hashified_body)
    end
  else
    @klazz.from_api(hashified_body.symbolize_keys!)
  end
end