Class: EADModel

Defined Under Namespace

Classes: IndexedArchivalObjectPrefetcher

Constant Summary collapse

RESOLVE =
['subjects', 'linked_agents', 'digital_object', 'top_container', 'top_container::container_profile']

Constants included from ASpaceExport::LazyChildEnumerations

ASpaceExport::LazyChildEnumerations::PREFETCH_SIZE

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ASpaceExport::LazyChildEnumerations

#children_indexes, #ensure_prefetched, #get_child

Methods included from ASpaceExport::ArchivalObjectDescriptionHelpers

#archdesc_dates, #archdesc_note_types, #bibliographies, #controlaccess_linked_agents, #controlaccess_subjects, #did_note_types, #index_item_type_map, #indexes

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, tree, opts) ⇒ EADModel

Returns a new instance of EADModel.



143
144
145
146
147
148
149
150
151
152
153
154
# File 'backend/app/exporters/models/ead.rb', line 143

def initialize(obj, tree, opts)
  @json = obj
  opts.each do |k, v|
    self.instance_variable_set("@#{k}", v)
  end

  repo_ref = obj.repository['ref']
  @repo_id = JSONModel::JSONModel(:repository).id_for(repo_ref)
  @repo = Repository.to_jsonmodel(@repo_id)
  @children = tree['children']
  @child_class = self.class.instance_variable_get(:@ao)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth) ⇒ Object



162
163
164
165
166
167
168
169
170
# File 'backend/app/exporters/models/ead.rb', line 162

def method_missing(meth)
  if self.instance_variable_get("@#{meth.to_s}")
    self.instance_variable_get("@#{meth.to_s}")
  elsif @json.respond_to?(meth)
    @json.send(meth)
  else
    nil
  end
end

Class Method Details

.data_src(json) ⇒ Object



27
28
29
# File 'backend/app/exporters/models/ead.rb', line 27

def self.data_src(json)
  @data_src.new(json)
end

.from_resource(obj, tree, opts) ⇒ Object



157
158
159
# File 'backend/app/exporters/models/ead.rb', line 157

def self.from_resource(obj, tree, opts)
  self.new(obj, tree, opts)
end

Instance Method Details

#addresslinesObject

EAD2002 address lines



205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
# File 'backend/app/exporters/models/ead.rb', line 205

def addresslines
  agent = self.agent_representation
  return [] unless agent && agent.agent_contacts[0]

  contact = agent.agent_contacts[0]

  data = []
  (1..3).each do |i|
    data << contact["address_#{i}"]
  end

  line = ""
  line += %w(city region).map {|k| contact[k] }.compact.join(', ')
  line += " #{contact['post_code']}"
  line.strip!

  data << line unless line.empty?

  if (telephones = contact['telephones'])
    telephones.each do |t|
      phone = ''
      if t['number_type'].nil?
        phone += "#{I18n.t('repository.telephone')}: "
      else
        phone += "#{t['number_type'].capitalize} #{I18n.t('telephone.number')}: "
      end
      phone += "#{t['number']}"
      phone += " (#{I18n.t('repository.telephone_ext')}: #{t['ext']})" if t['ext']

      data << phone unless phone.empty?
    end
  end

  data << contact['email'] if contact['email']

  data.compact!

  data
end

#addresslines_keyedObject

EAD3 address lines



247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'backend/app/exporters/models/ead.rb', line 247

def addresslines_keyed
  agent = self.agent_representation
  return [] unless agent && agent.agent_contacts[0]

  contact = agent.agent_contacts[0]

  data = {}
  (1..3).each do |i|
    data["address_#{i}"] = contact["address_#{i}"]
  end

  line = ""
  line += %w(city region).map {|k| contact[k] }.compact.join(', ')
  line += " #{contact['post_code']}"
  line.strip!
  data['city_region_post_code'] = line unless line.empty?

  if (telephones = contact['telephones'])
    telephones.each_with_index do |t, i|
      data["telephone_#{i}"] = []
      if t['number_type'].nil?
        data["telephone_#{i}"] << "#{I18n.t('repository.telephone').downcase}"
      else
        data["telephone_#{i}"] << t['number_type']
      end

      data["telephone_#{i}"] << t['number']
      data["telephone_#{i}"][1] += " (#{I18n.t('repository.telephone_ext')}: #{t['ext']})" if t['ext']
    end
  end

  data['email'] = contact['email']

  data.delete_if { |k, v| v.nil? }

  data
end

#agent_representationObject



194
195
196
197
198
199
200
201
# File 'backend/app/exporters/models/ead.rb', line 194

def agent_representation
  return false unless @repo['agent_representation_id']

  agent_id = @repo['agent_representation_id']
  json = AgentCorporateEntity.to_jsonmodel(agent_id)

  json
end

#creators_and_sourcesObject



303
304
305
# File 'backend/app/exporters/models/ead.rb', line 303

def creators_and_sources
  self.linked_agents.select {|link| ['creator', 'source'].include?(link['role']) }
end

#descrulesObject



286
287
288
289
290
# File 'backend/app/exporters/models/ead.rb', line 286

def descrules
  return nil unless @descrules || self.finding_aid_description_rules
  @descrules ||= I18n.t("enumerations.resource_finding_aid_description_rules.#{self.finding_aid_description_rules}", :default => self.finding_aid_description_rules)
  @descrules
end

#digital_objectsObject



308
309
310
311
312
313
314
# File 'backend/app/exporters/models/ead.rb', line 308

def digital_objects
  if @include_daos
    self.instances.select {|inst| inst['digital_object']}.compact.map {|inst| inst['digital_object']['_resolved'] }.compact
  else
    []
  end
end

#include_daos?Boolean

Returns:

  • (Boolean)


178
179
180
# File 'backend/app/exporters/models/ead.rb', line 178

def include_daos?
  @include_daos
end

#include_unpublished?Boolean

Returns:

  • (Boolean)


173
174
175
# File 'backend/app/exporters/models/ead.rb', line 173

def include_unpublished?
  @include_unpublished
end

#instances_with_digital_objectsObject



298
299
300
# File 'backend/app/exporters/models/ead.rb', line 298

def instances_with_digital_objects
  self.instances.select {|inst| inst['digital_object']}.compact
end

#instances_with_sub_containersObject



293
294
295
# File 'backend/app/exporters/models/ead.rb', line 293

def instances_with_sub_containers
  self.instances.select {|inst| inst['sub_container']}.compact
end

#mainagencycodeObject



188
189
190
191
# File 'backend/app/exporters/models/ead.rb', line 188

def mainagencycode
  @mainagencycode ||= repo.country && repo.org_code ? [repo.country, repo.org_code].join('-') : nil
  @mainagencycode
end

#metadata_rights_declaration_in_publicationstmtObject



316
317
318
319
320
321
322
# File 'backend/app/exporters/models/ead.rb', line 316

def 
  must_be_empty = %w(file_uri)
  @json..each do |mrd|
    next if must_be_empty.find { |property| !mrd[property].to_s.empty? }
    yield mrd
  end
end

#metadata_rights_declaration_in_rightsdeclarationObject



324
325
326
327
328
329
330
# File 'backend/app/exporters/models/ead.rb', line 324

def 
  must_not_be_empty = %w(file_uri)
  @json..each do |mrd|
    next unless must_not_be_empty.find { |property| !mrd[property].to_s.empty? }
    yield mrd
  end
end

#use_numbered_c_tags?Boolean

Returns:

  • (Boolean)


183
184
185
# File 'backend/app/exporters/models/ead.rb', line 183

def use_numbered_c_tags?
  @use_numbered_c_tags
end