Class: Hypermicrodata::Serializer::Hal

Inherits:
Base
  • Object
show all
Defined in:
lib/hypermicrodata/serializer/hal.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize, #to_json

Constructor Details

This class inherits a constructor from Hypermicrodata::Serializer::Base

Instance Method Details

#serializeObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/hypermicrodata/serializer/hal.rb', line 4

def serialize
  items = @document.items
  if items.length == 1
    hal_resource = item_to_resource(items.first, @location)
  else
    hal_resource = Halibut::Core::Resource.new(@location)
    items.each do |item|
      embedded_resource = item_to_resource(item)
      item.type.each do |type|
        hal_resource.add_embedded_resource(type, embedded_resource)
      end
    end
  end
  hal_resource.add_link('profile', @profile_path) if @profile_path
  hal_resource.to_hash
end