Module: SerializeExtraContainerValues

Included in:
EADSerializer
Defined in:
backend/app/exporters/lib/serialize_extra_container_values.rb

Defined Under Namespace

Classes: AltRenderCalculator

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) included(base)



23
24
25
26
27
28
29
# File 'backend/app/exporters/lib/serialize_extra_container_values.rb', line 23

def self.included(base)
  base.class_eval do
    def serialize_container(inst, xml, fragments)
      manage_containers_serialize_container(inst, xml, fragments)
    end
  end
end

Instance Method Details

- (Object) altrender_calculator



31
32
33
34
35
# File 'backend/app/exporters/lib/serialize_extra_container_values.rb', line 31

def altrender_calculator
  # Each EAD export gets its own serializer instance, so we can safely store
  # state between calls here.
  @altrender_calculator ||= AltRenderCalculator.new
end

- (Object) manage_containers_serialize_container(inst, xml, fragments)



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'backend/app/exporters/lib/serialize_extra_container_values.rb', line 37

def manage_containers_serialize_container(inst, xml, fragments)
  @parent_id = nil
  (1..3).each do |n|
    atts = {}
    next unless inst['container'].has_key?("type_#{n}") && inst['container'].has_key?("indicator_#{n}")
    @container_id = prefix_id(SecureRandom.hex)

    atts[:parent] = @parent_id unless @parent_id.nil?
    atts[:id] = @container_id
    @parent_id = @container_id

    atts[:type] = inst['container']["type_#{n}"]
    text = inst['container']["indicator_#{n}"]

    if n == 1 && inst['instance_type']
      atts[:label] = I18n.t("enumerations.instance_instance_type.#{inst['instance_type']}", :default => inst['instance_type'])
      if inst['container']['barcode_1']
        atts[:label] << " [#{inst['container']['barcode_1']}]"
      end

      if inst['sub_container'] && inst['sub_container']['top_container']
        if (altrender = altrender_calculator.for_top_container_uri(inst['sub_container']['top_container']['ref']))
          atts[:altrender] = altrender
        end
      end
    end

    xml.container(atts) {
      sanitize_mixed_content(text, xml, fragments)
    }
  end
end