Class: MARCModel
- Inherits:
-
ASpaceExport::ExportModel
- Object
- ASpaceExport::ExportModel
- MARCModel
- Includes:
- JSONModel
- Defined in:
- backend/app/exporters/models/marc21.rb
Constant Summary
- @@datafield =
Class.new do
- @@subfield =
Class.new do
Instance Attribute Summary (collapse)
-
- (Object) controlfield_string
Returns the value of attribute controlfield_string.
-
- (Object) leader_string
Returns the value of attribute leader_string.
Class Method Summary (collapse)
-
+ (Object) assemble_controlfield_string(obj)
-
+ (Object) df_handler(name, tag, ind1, ind2, code)
-
+ (Object) from_archival_object(obj)
‘archival object’s in the abstract.
-
+ (Object) from_aspace_object(obj)
-
+ (Object) from_resource(obj)
subtypes of ‘archival object’:.
Instance Method Summary (collapse)
-
- (Object) datafields
-
- (Object) df(*args)
-
- (Object) df!(*args)
-
- (Object) handle_agents(linked_agents)
-
- (Object) handle_dates(dates)
-
- (Object) handle_ead_loc(ead_loc)
-
- (Object) handle_extents(extents)
-
- (Object) handle_id(*ids)
-
- (Object) handle_language(langcode)
-
- (Object) handle_notes(notes)
-
- (Object) handle_primary_creator(linked_agents)
-
- (Object) handle_repo_code(repository)
-
- (Object) handle_subjects(subjects)
-
- (Object) handle_title(title)
-
- (MARCModel) initialize
constructor
A new instance of MARCModel.
-
- (Object) source_to_code(source)
Methods included from JSONModel
JSONModel, #JSONModel, add_error_handler, all, allow_unmapped_enum_value, backend_url, client_mode?, custom_validations, destroy_model, enum_default_value, enum_values, handle_error, init, load_schema, #models, models, parse_jsonmodel_ref, parse_reference, repository, repository_for, schema_src, set_repository, strict_mode, strict_mode?, with_repository
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
- (MARCModel) initialize
Returns a new instance of MARCModel
75 76 77 |
# File 'backend/app/exporters/models/marc21.rb', line 75 def initialize @datafields = {} end |
Instance Attribute Details
- (Object) controlfield_string
Returns the value of attribute controlfield_string
31 32 33 |
# File 'backend/app/exporters/models/marc21.rb', line 31 def controlfield_string @controlfield_string end |
- (Object) leader_string
Returns the value of attribute leader_string
30 31 32 |
# File 'backend/app/exporters/models/marc21.rb', line 30 def leader_string @leader_string end |
Class Method Details
+ (Object) assemble_controlfield_string(obj)
112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'backend/app/exporters/models/marc21.rb', line 112 def self.assemble_controlfield_string(obj) date = obj.dates[0] || {} string = obj['system_mtime'].scan(/\d{2}/)[1..3].join('') string += obj.level == 'item' && date['date_type'] == 'single' ? 's' : 'i' string += date['begin'] ? date['begin'][0..3] : " " string += date['end'] ? date['end'][0..3] : " " string += "xx" 18.times { string += ' ' } string += (obj.language || '|||') string += ' d' string end |
+ (Object) df_handler(name, tag, ind1, ind2, code)
6 7 8 9 10 11 |
# File 'backend/app/exporters/models/marc21.rb', line 6 def self.df_handler(name, tag, ind1, ind2, code) define_method(name) do |val| df(tag, ind1, ind2).with_sfs([code, val]) end name.to_sym end |
+ (Object) from_archival_object(obj)
‘archival object’s in the abstract
89 90 91 92 93 94 95 96 |
# File 'backend/app/exporters/models/marc21.rb', line 89 def self.from_archival_object(obj) marc = self.from_aspace_object(obj) marc.apply_map(obj, @archival_object_map) marc end |
+ (Object) from_aspace_object(obj)
84 85 86 |
# File 'backend/app/exporters/models/marc21.rb', line 84 def self.from_aspace_object(obj) self.new end |
+ (Object) from_resource(obj)
subtypes of ‘archival object’:
100 101 102 103 104 105 106 107 108 109 |
# File 'backend/app/exporters/models/marc21.rb', line 100 def self.from_resource(obj) marc = self.from_archival_object(obj) marc.apply_map(obj, @resource_map) marc.leader_string = "00000np$ a2200000 u 4500" marc.leader_string[7] = obj.level == 'item' ? 'm' : 'c' marc.controlfield_string = assemble_controlfield_string(obj) marc end |
Instance Method Details
- (Object) datafields
79 80 81 |
# File 'backend/app/exporters/models/marc21.rb', line 79 def datafields @datafields.map {|k,v| v} end |
- (Object) df(*args)
135 136 137 138 139 140 141 142 |
# File 'backend/app/exporters/models/marc21.rb', line 135 def df(*args) if @datafields.has_key?(args.to_s) @datafields[args.to_s] else @datafields[args.to_s] = @@datafield.new(*args) @datafields[args.to_s] end end |
- (Object) df!(*args)
127 128 129 130 131 132 |
# File 'backend/app/exporters/models/marc21.rb', line 127 def df!(*args) @sequence ||= 0 @sequence += 1 @datafields[@sequence] = @@datafield.new(*args) @datafields[@sequence] end |
- (Object) handle_agents(linked_agents)
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'backend/app/exporters/models/marc21.rb', line 300 def handle_agents(linked_agents) handle_primary_creator(linked_agents) subjects = linked_agents.select{|a| a['role'] == 'subject'} subjects.each_with_index do |link, i| subject = link['_resolved'] name = subject['display_name'] relator = link['relator'] terms = link['terms'] ind2 = source_to_code(name['source']) case subject['agent_type'] when 'agent_corporate_entity' code = '610' ind1 = '2' sfs = [ ['a', name['primary_name']], ['b', name['subordinate_name_1']], ['b', name['subordinate_name_2']], ['n', name['number']], ['g', name['qualifier']], ] when 'agent_person' joint, ind1 = name['name_order'] == 'direct' ? [' ', '0'] : [', ', '1'] name_parts = [name['primary_name'], name['rest_of_name']].reject{|i| i.nil? || i.empty?}.join(joint) ind1 = name['name_order'] == 'direct' ? '0' : '1' code = '600' sfs = [ ['a', name_parts], ['b', name['number']], ['c', %w(prefix title suffix).map {|prt| name[prt]}.compact.join(', ')], ['q', name['fuller_form']], ['d', name['dates']], ['g', name['qualifier']], ] when 'agent_family' code = '600' ind1 = '3' sfs = [ ['a', name['family_name']], ['c', name['prefix']], ['d', name['dates']], ['g', name['qualifier']], ] end terms.each do |t| tag = case t['term_type'] when 'uniform_title'; 't' when 'genre_form', 'style_period'; 'v' when 'topical', 'cultural_context'; 'x' when 'temporal'; 'y' when 'geographic'; 'z' end sfs << [(tag), t['term']] end if ind2 == '7' sfs << ['2', subject['source']] end df(code, ind1, ind2, i).with_sfs(*sfs) end creators = linked_agents.select{|a| a['role'] == 'creator'}[1..-1] || [] creators = creators + linked_agents.select{|a| a['role'] == 'source'} creators.each do |link| creator = link['_resolved'] name = creator['display_name'] relator = link['relator'] terms = link['terms'] role = link['role'] if relator relator_sf = ['4', relator] elsif role == 'source' relator_sf = ['e', 'former owner'] else relator_sf = ['e', 'creator'] end ind2 = ' ' case creator['agent_type'] when 'agent_corporate_entity' code = '710' ind1 = '2' sfs = [ ['a', name['primary_name']], ['b', name['subordinate_name_1']], ['b', name['subordinate_name_2']], ['n', name['number']], ['g', name['qualifier']], ] when 'agent_person' joint, ind1 = name['name_order'] == 'direct' ? [' ', '0'] : [', ', '1'] name_parts = [name['primary_name'], name['rest_of_name']].reject{|i| i.nil? || i.empty?}.join(joint) ind1 = name['name_order'] == 'direct' ? '0' : '1' code = '700' sfs = [ ['a', name_parts], ['b', name['number']], ['c', %w(prefix title suffix).map {|prt| name[prt]}.compact.join(', ')], ['q', name['fuller_form']], ['d', name['dates']], ['g', name['qualifier']], ] when 'agent_family' ind1 = '3' code = '700' sfs = [ ['a', name['family_name']], ['c', name['prefix']], ['d', name['dates']], ['g', name['qualifier']], ] end sfs << relator_sf df(code, ind1, ind2).with_sfs(*sfs) end end |
- (Object) handle_dates(dates)
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
# File 'backend/app/exporters/models/marc21.rb', line 164 def handle_dates(dates) return false if dates.empty? dates = [["single", "inclusive", "range"], ["bulk"]].map {|types| dates.find {|date| types.include? date['date_type'] } }.compact dates.each do |date| code = date['date_type'] == 'bulk' ? 'g' : 'f' val = nil if date['expression'] && date['date_type'] != 'bulk' val = date['expression'] elsif date['date_type'] == 'single' val = date['begin'] else val = "#{date['begin']} - #{date['end']}" end df('245', '1', '0').with_sfs([code, val]) end end |
- (Object) handle_ead_loc(ead_loc)
517 518 519 520 521 522 523 524 525 526 |
# File 'backend/app/exporters/models/marc21.rb', line 517 def handle_ead_loc(ead_loc) df('555', ' ', ' ').with_sfs( ['a', "Finding aid online:"], ['u', ead_loc] ) df('856', '4', '2').with_sfs( ['z', "Finding aid online:"], ['u', ead_loc] ) end |
- (Object) handle_extents(extents)
503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'backend/app/exporters/models/marc21.rb', line 503 def handle_extents(extents) extents.each do |ext| e = ext['number'] e << " #{I18n.t('enumerations.extent_extent_type.'+ext['extent_type'], :default => ext['extent_type'])}" if ext['container_summary'] e << " (#{ext['container_summary']})" end df!('300').with_sfs(['a', e]) end end |
- (Object) handle_id(*ids)
145 146 147 148 149 |
# File 'backend/app/exporters/models/marc21.rb', line 145 def handle_id(*ids) ids.reject!{|i| i.nil? || i.empty?} df('099', ' ', ' ').with_sfs(['a', ids.join('.')]) df('852', ' ', ' ').with_sfs(['c', ids.join('.')]) end |
- (Object) handle_language(langcode)
157 158 159 160 161 |
# File 'backend/app/exporters/models/marc21.rb', line 157 def handle_language(langcode) df('041', '0', ' ').with_sfs(['a', langcode]) df('040', '0', ' ').with_sfs(['b', langcode]) df('049', '0', ' ').with_sfs(['a', langcode]) end |
- (Object) handle_notes(notes)
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'backend/app/exporters/models/marc21.rb', line 436 def handle_notes(notes) notes.each do |note| prefix = case note['type'] when 'dimensions'; "Dimensions" when 'physdesc'; "Physical Description note" when 'materialspec'; "Material Specific Details" when 'physloc'; "Location of resource" when 'phystech'; "Physical Characteristics / Technical Requirements" when 'physfacet'; "Physical Facet" when 'processinfo'; "Processing Information" when 'separatedmaterial'; "Materials Separated from the Resource" else; nil end marc_args = case note['type'] when 'arrangement', 'fileplan' ['351','b'] when 'odd', 'dimensions', 'physdesc', 'materialspec', 'physloc', 'phystech', 'physfacet', 'processinfo', 'separatedmaterial' ['500','a'] when 'accessrestrict' ['506','a'] when 'scopecontent' ['520', '2', ' ', 'a'] when 'abstract' ['520', '3', ' ', 'a'] when 'prefercite' ['524', '8', ' ', 'a'] when 'acqinfo' ind1 = note['publish'] ? '1' : '0' ['541', ind1, ' ', 'a'] when 'relatedmaterial' ['544','a'] when 'bioghist' ['545','a'] when 'custodhist' ind1 = note['publish'] ? '1' : '0' ['561', ind1, ' ', 'a'] when 'appraisal' ind1 = note['publish'] ? '1' : '0' ['583', ind1, ' ', 'a'] when 'accruals' ['584', 'a'] when 'altformavail' ['535', '2', ' ', 'a'] when 'originalsloc' ['535', '1', ' ', 'a'] when 'userestrict', 'legalstatus' ['540', 'a'] when 'langmaterial' ['546', 'a'] else nil end unless marc_args.nil? text = prefix ? "#{prefix}: " : "" text += ASpaceExport::Utils.extract_note_text(note) df!(*marc_args[0...-1]).with_sfs([marc_args.last, *Array(text)]) end end end |
- (Object) handle_primary_creator(linked_agents)
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 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'backend/app/exporters/models/marc21.rb', line 247 def handle_primary_creator(linked_agents) link = linked_agents.find{|a| a['role'] == 'creator'} return nil unless link creator = link['_resolved'] name = creator['display_name'] ind2 = ' ' role_info = link['relator'] ? ['4', link['relator']] : ['e', 'creator'] case creator['agent_type'] when 'agent_corporate_entity' code = '110' ind1 = '2' sfs = [ ['a', name['primary_name']], ['b', name['subordinate_name_1']], ['b', name['subordinate_name_2']], ['n', name['number']], ['d', name['dates']], ['g', name['qualifier']], ] when 'agent_person' joint, ind1 = name['name_order'] == 'direct' ? [' ', '0'] : [', ', '1'] name_parts = [name['primary_name'], name['rest_of_name']].reject{|i| i.nil? || i.empty?}.join(joint) code = '100' sfs = [ ['a', name_parts], ['b', name['number']], ['c', %w(prefix title suffix).map {|prt| name[prt]}.compact.join(', ')], ['q', name['fuller_form']], ['d', name['dates']], ['g', name['qualifier']], ] when 'agent_family' code = '100' ind1 = '3' sfs = [ ['a', name['family_name']], ['c', name['prefix']], ['d', name['dates']], ['g', name['qualifier']], ] end sfs << role_info df(code, ind1, ind2).with_sfs(*sfs) end |
- (Object) handle_repo_code(repository)
186 187 188 189 190 191 192 193 194 195 196 197 |
# File 'backend/app/exporters/models/marc21.rb', line 186 def handle_repo_code(repository) repo = repository['_resolved'] return false unless repo sfa = repo['org_code'] ? repo['org_code'] : "Repository: #{repo['repo_code']}" df('852', ' ', ' ').with_sfs( ['a', sfa], ['b', repo['name']] ) df('040', ' ', ' ').with_sfs(['a', repo['org_code']], ['c', repo['org_code']]) end |
- (Object) handle_subjects(subjects)
203 204 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 244 |
# File 'backend/app/exporters/models/marc21.rb', line 203 def handle_subjects(subjects) subjects.each do |link| subject = link['_resolved'] term, *terms = subject['terms'] code, ind2 = case term['term_type'] when 'uniform_title' ['630', source_to_code(subject['source'])] when 'temporal' ['648', source_to_code(subject['source'])] when 'topical' ['650', source_to_code(subject['source'])] when 'geographic', 'cultural_context' ['651', source_to_code(subject['source'])] when 'genre_form', 'style_period' ['655', source_to_code(subject['source'])] when 'occupation' ['656', '7'] when 'function' ['656', '7'] else ['650', source_to_code(subject['source'])] end sfs = [['a', term['term']]] terms.each do |t| tag = case t['term_type'] when 'uniform_title'; 't' when 'genre_form', 'style_period'; 'v' when 'topical', 'cultural_context'; 'x' when 'temporal'; 'y' when 'geographic'; 'z' end sfs << [tag, t['term']] end if ind2 == '7' sfs << ['2', subject['source']] end df!(code, ' ', ind2).with_sfs(*sfs) end end |
- (Object) handle_title(title)
152 153 154 |
# File 'backend/app/exporters/models/marc21.rb', line 152 def handle_title(title) df('245', '1', '0').with_sfs(['a', title]) end |
- (Object) source_to_code(source)
199 200 201 |
# File 'backend/app/exporters/models/marc21.rb', line 199 def source_to_code(source) ASpaceMappings::MARC21.get_marc_source_code(source) end |