Method: Item#export

Defined in:
lib/item.rb

#exportObject

The export method serializes all of the formats, ID, and previous ID into a hash that is used for publishing to clients. If more than one instance of the same type of Format implementation was specified then an error will be raised.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/item.rb', line 34

def export
  format_types = []
  @formats.each do |format|
    if !format_types.index(format.class.name).nil?
      raise 'more than one instance of ' + format.class.name + ' specified'
    end
    format_types.push(format.class.name)
  end
  out = Hash.new
  if !@id.nil?
    out['id'] = @id
  end
  if !@prev_id.nil?
    out['prev-id'] = @prev_id
  end
  @formats.each do |format|
    out[format.name] = format.export
  end
  return out
end