Class: EADModel

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

Defined Under Namespace

Classes: IndexedArchivalObjectPrefetcher

Constant Summary collapse

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ASpaceExport::ExportModel

#apply_map, inherited, model_for, model_for?

Constructor Details

#initialize(obj, tree, opts) ⇒ EADModel

Returns a new instance of EADModel.

[View source]

133
134
135
136
137
138
139
140
141
142
143
144
# File 'backend/app/exporters/models/ead.rb', line 133

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

[View source]

152
153
154
155
156
157
158
159
160
# File 'backend/app/exporters/models/ead.rb', line 152

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

[View source]

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

[View source]

147
148
149
# File 'backend/app/exporters/models/ead.rb', line 147

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

Instance Method Details

#addresslinesObject

EAD2002 address lines

[View source]

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
244
245
246
247
248
249
250
# File 'backend/app/exporters/models/ead.rb', line 212

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

[View source]

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
284
285
286
287
288
289
290
# File 'backend/app/exporters/models/ead.rb', line 254

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

[View source]

201
202
203
204
205
206
207
208
# File 'backend/app/exporters/models/ead.rb', line 201

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

[View source]

300
301
302
# File 'backend/app/exporters/models/ead.rb', line 300

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

#descrulesObject

[View source]

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

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

#include_daos?Boolean

Returns:

  • (Boolean)
[View source]

168
169
170
# File 'backend/app/exporters/models/ead.rb', line 168

def include_daos?
  @include_daos
end

#include_unpublished?Boolean

Returns:

  • (Boolean)
[View source]

163
164
165
# File 'backend/app/exporters/models/ead.rb', line 163

def include_unpublished?
  @include_unpublished
end

#include_urisObject

Defaults to true if @include_uris is not defined or its value is nil.

[View source]

179
180
181
182
183
184
185
186
187
# File 'backend/app/exporters/models/ead.rb', line 179

def include_uris
  if instance_variable_defined?(:@include_uris)
    @include_uris = true if @include_uris.nil?

    return @include_uris
  end

  @include_uris = true
end

#include_uris?Boolean

Returns:

  • (Boolean)
[View source]

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

def include_uris?
  include_uris
end

#mainagencycodeObject

[View source]

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

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

#metadata_rights_declaration_in_publicationstmtObject

[View source]

305
306
307
308
309
310
311
# File 'backend/app/exporters/models/ead.rb', line 305

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

[View source]

313
314
315
316
317
318
319
# File 'backend/app/exporters/models/ead.rb', line 313

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)
[View source]

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

def use_numbered_c_tags?
  @use_numbered_c_tags
end