Class: Hypermicrodata::Serializer::Base

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

Direct Known Subclasses

Hal, Jsonld, Uber

Instance Method Summary collapse

Constructor Details

#initialize(document, location = nil, profile_path = nil) ⇒ Base

Returns a new instance of Base.



4
5
6
7
8
# File 'lib/hypermicrodata/serializer/base.rb', line 4

def initialize(document, location = nil, profile_path = nil)
  @document = document
  @location = location
  @profile_path = profile_path
end

Instance Method Details

#serializeObject



14
15
16
17
18
19
20
21
# File 'lib/hypermicrodata/serializer/base.rb', line 14

def serialize
  # return hash or array suitable for application/json
  if @document.items
    @document.items.map(&:to_hash)
  else
    []
  end
end

#to_json(options = {}) ⇒ Object



10
11
12
# File 'lib/hypermicrodata/serializer/base.rb', line 10

def to_json(options = {})
  MultiJson.dump(serialize, options)
end