Module: BerkeleyLibrary::TIND::Mapping::Util

Class Method Summary collapse

Class Method Details

.alma_datafield(tag, record) ⇒ Object



60
61
62
63
# File 'lib/berkeley_library/tind/mapping/util.rb', line 60

def alma_datafield(tag, record)
  record.fields.each { |f| return f if f.tag.to_s == tag }
  nil
end

.concatenation_symbol(str) ⇒ Object



20
21
22
# File 'lib/berkeley_library/tind/mapping/util.rb', line 20

def concatenation_symbol(str)
  str ? str.gsub('a', ' ') : ' '
end

.csv_rows(file) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/berkeley_library/tind/mapping/util.rb', line 11

def csv_rows(file)
  rows = []
  CSV.foreach(file, headers: true, header_converters: :symbol, encoding: 'bom|utf-8') do |row|
    # puts row.headers
    rows << clr_row(row)
  end
  rows
end

.datafield(tag, indicator, subfields) ⇒ Object



34
35
36
37
38
# File 'lib/berkeley_library/tind/mapping/util.rb', line 34

def datafield(tag, indicator, subfields)
  datafield = ::MARC::DataField.new(tag, indicator[0], indicator[1])
  subfields.each { |sf| datafield.append(sf) }
  datafield
end

.from_xml(xml) ⇒ MARC::Record?

From DM - get testing MARC from xml file

Parameters:

  • xml (String)

    the XML to parse

Returns:

  • (MARC::Record, nil)

    the MARC record from the specified XML



76
77
78
79
# File 'lib/berkeley_library/tind/mapping/util.rb', line 76

def from_xml(xml)
  # noinspection RubyYardReturnMatch,RubyMismatchedReturnType
  all_from_xml(xml).first
end

.indicator(str) ⇒ Object



24
25
26
27
28
# File 'lib/berkeley_library/tind/mapping/util.rb', line 24

def indicator(str)
  return [] unless str

  str.strip.gsub('_', ' ').split(',')
end

.qualified_alma_record?(alma_record) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
69
70
71
# File 'lib/berkeley_library/tind/mapping/util.rb', line 65

def qualified_alma_record?(alma_record)
  f_245 = alma_datafield('245', alma_record)
  f_245_a = f_245['a'].downcase

  val = 'Host bibliographic record'.downcase
  !f_245_a.start_with? val
end

.remove_extra_symbol(rules, val) ⇒ Object



54
55
56
57
58
# File 'lib/berkeley_library/tind/mapping/util.rb', line 54

def remove_extra_symbol(rules, val)
  symbols = symbols(rules)
  symbols.each { |s| val = val.strip.delete_suffix(s) }
  val
end

.subfield(code, value) ⇒ Object



40
41
42
# File 'lib/berkeley_library/tind/mapping/util.rb', line 40

def subfield(code, value)
  ::MARC::Subfield.new(code, value)
end

.subfield_hash(field) ⇒ Object



44
45
46
47
# File 'lib/berkeley_library/tind/mapping/util.rb', line 44

def subfield_hash(field)
  code_value_arr = field.to_hash[field.tag]['subfields']
  {}.tap { |i| code_value_arr.each(&i.method(:update)) }
end

.symbols(rules) ⇒ Object

input an array of rules, example: [["a,b,c,d", "b", "--"],["o,p,q", "b", ""]]



50
51
52
# File 'lib/berkeley_library/tind/mapping/util.rb', line 50

def symbols(rules)
  rules.map { |rule| concatenation_symbol(rule[2]).strip }
end

.tag_symbol(tag) ⇒ Object



30
31
32
# File 'lib/berkeley_library/tind/mapping/util.rb', line 30

def tag_symbol(tag)
  "tag_#{tag}".to_sym
end