Class: MARCSerializer

Inherits:
ASpaceExport::Serializer show all
Defined in:
backend/app/exporters/serializers/marc21.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASpaceExport::Serializer

inherited, serializer_for, serializer_for?, with_namespace

Class Method Details

.add_decorator(decorator) ⇒ Object

Allow plugins to wrap the MARC record with their own behavior. Gives them the chance to change the leader, 008, add extra data fields, etc.



14
15
16
17
# File 'backend/app/exporters/serializers/marc21.rb', line 14

def self.add_decorator(decorator)
  @decorators ||= []
  @decorators << decorator
end

.decorate_record(record) ⇒ Object



19
20
21
22
23
# File 'backend/app/exporters/serializers/marc21.rb', line 19

def self.decorate_record(record)
  Array(@decorators).reduce(record) {|result, decorator|
    decorator.new(result)
  }
end

Instance Method Details

#build(marc, opts = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'backend/app/exporters/serializers/marc21.rb', line 4

def build(marc, opts = {})
  builder = Nokogiri::XML::Builder.new(:encoding => "UTF-8") do |xml|
    _root(marc, xml)
  end

  builder
end

#serialize(marc, opts = {}) ⇒ Object



26
27
28
29
30
# File 'backend/app/exporters/serializers/marc21.rb', line 26

def serialize(marc, opts = {})
  builder = build(MARCSerializer.decorate_record(marc), opts)

  builder.to_xml
end