Class: MARCAuthModel

Inherits:
ASpaceExport::ExportModel show all
Defined in:
backend/app/exporters/models/marc_auth.rb

Overview

frozen_string_literal: true

Constant Summary collapse

RESOLVE =
['subjects', 'places'].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASpaceExport::ExportModel

#apply_map, inherited, model_for, model_for?

Methods included from ASpaceExport::ExportModelHelpers

#extract_date_string, #extract_note_content, #get_subnotes_by_type

Constructor Details

#initialize(obj, events, related_records, repo) ⇒ MARCAuthModel

Returns a new instance of MARCAuthModel.



57
58
59
60
61
62
63
# File 'backend/app/exporters/models/marc_auth.rb', line 57

def initialize(obj, events, related_records, repo)
  @type = obj.jsonmodel_type
  @json = URIResolver.resolve_references(obj, RESOLVE)
  @events = events.map { |e| self.class.instance_variable_get(:@marc_auth_event).new(e) }
  @related_records = related_records
  @repo = repo
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object



81
82
83
# File 'backend/app/exporters/models/marc_auth.rb', line 81

def method_missing(meth)
  @json.send(meth) if @json.respond_to?(meth)
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events



69
70
71
# File 'backend/app/exporters/models/marc_auth.rb', line 69

def events
  @events
end

#jsonObject (readonly)

Returns the value of attribute json



6
7
8
# File 'backend/app/exporters/models/marc_auth.rb', line 6

def json
  @json
end

Returns the value of attribute related_records



6
7
8
# File 'backend/app/exporters/models/marc_auth.rb', line 6

def related_records
  @related_records
end

Class Method Details

.from_agent(obj, events, related_records, repo) ⇒ Object



65
66
67
# File 'backend/app/exporters/models/marc_auth.rb', line 65

def self.from_agent(obj, events, related_records, repo)
  new(obj, events, related_records, repo)
end

Instance Method Details

#maintenanceAgencyObject



71
72
73
74
75
76
77
78
79
# File 'backend/app/exporters/models/marc_auth.rb', line 71

def maintenanceAgency
  if @ma.nil?
    @ma = OpenStruct.new
    @ma.agencyName = @repo.name
    @ma.agencyCode = @repo.org_code if @repo.org_code
  end

  @ma
end

#name_part_fieldsObject

maps name.field => EAC @localType attribute



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'backend/app/exporters/models/marc_auth.rb', line 94

def name_part_fields
  case @type
  when 'agent_person'
    {
      'primary_name' => 'surname',
      'title' => 'title',
      'prefix' => 'prefix',
      'rest_of_name' => 'forename',
      'suffix' => 'suffix',
      'fuller_form' => 'fuller_form',
      'number' => 'numeration',
      'qualifier' => 'qualifier',
      'dates' => 'dates'
    }
  when 'agent_family'
    {
      'prefix' => 'prefix',
      'family_name' => 'surname',
      'number' => 'numeration',
      'qualifier' => 'qualifier',
      'location' => 'location',
      'dates' => 'dates',
      'family_type' => 'family_type'
    }
  # TODO: Remove software?
  when 'agent_software'
    {
      'software_name' => nil,
      'version' => nil,
      'manufacturer' => nil
    }
  when 'agent_corporate_entity'
    {
      'primary_name' => 'primary_name',
      'subordinate_name_1' => 'subordinate_name_1',
      'subordinate_name_2' => 'subordinate_name_2',
      'number' => 'numeration',
      'qualifier' => 'qualifier',
      'location' => 'location',
      'dates' => 'dates'
    }
  end
end


85
86
87
88
89
90
91
# File 'backend/app/exporters/models/marc_auth.rb', line 85

def related_agents
  if @json.respond_to?(:related_agents)
    @json.related_agents
  else
    []
  end
end