Class: MARC::DublinCore

Inherits:
Object
  • Object
show all
Defined in:
lib/marc/dublincore.rb

Overview

A class for mapping MARC records to Dublin Core

Class Method Summary collapse

Class Method Details

.get_field_value(field) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/marc/dublincore.rb', line 82

def self.get_field_value(field)
  return if field.nil?

  if !field.is_a?(String) && field.respond_to?(:each)
    values = []
    field.each do |element|
      values << get_field_value(element)
    end
    values
  else
    return field if field.is_a?(String)
    return field.value if field.respond_to?(:value)
  end
end

.map(record) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/marc/dublincore.rb', line 5

def self.map(record)
  dc_hash = {}
  dc_hash["title"] = get_field_value(record["245"]["a"])

  # Creator
  ["100", "110", "111", "700", "710", "711", "720"].each do |field|
    dc_hash["creator"] ||= []
    dc_hash["creator"] << get_field_value(record[field])
  end

  # Subject
  ["600", "610", "611", "630", "650", "653"].each do |field|
    dc_hash["subject"] ||= []
    dc_hash["subject"] << get_field_value(record[field])
  end

  # Description
  ("500".."599").each do |field|
    next if ["506", "530", "540", "546"].include?(field)
    dc_hash["description"] ||= []
    dc_hash["description"] << get_field_value(record[field])
  end

  dc_hash["publisher"] = begin
    get_field_value(record["260"]["a"]["b"])
  rescue
    nil
  end
  dc_hash["date"] = begin
    get_field_value(record["260"]["c"])
  rescue
    nil
  end
  dc_hash["type"] = get_field_value(record["655"])
  dc_hash["format"] = begin
    get_field_value(record["856"]["q"])
  rescue
    nil
  end
  dc_hash["identifier"] = begin
    get_field_value(record["856"]["u"])
  rescue
    nil
  end
  dc_hash["source"] = begin
    get_field_value(record["786"]["o"]["t"])
  rescue
    nil
  end
  dc_hash["language"] = get_field_value(record["546"])

  dc_hash["relation"] = []
  dc_hash["relation"] << get_field_value(record["530"])
  ("760".."787").each do |field|
    dc_hash["relation"] << get_field_value(record[field]["o"]["t"])
  rescue
    nil
  end

  ["651", "752"].each do |field|
    dc_hash["coverage"] ||= []
    dc_hash["coverage"] << get_field_value(record[field])
  end

  ["506", "540"].each do |field|
    dc_hash["rights"] ||= []
    dc_hash["rights"] << get_field_value(record[field])
  end

  dc_hash.keys.each do |key|
    dc_hash[key].flatten! if dc_hash[key].respond_to?(:flatten!)
    dc_hash[key].compact! if dc_hash[key].respond_to?(:compact!)
  end

  dc_hash
end