Module: Macros::MetCsv

Defined in:
lib/macros/met_csv.rb

Overview

Macros for extracting values from CSV rows

Constant Summary collapse

DISPLAY_NAME =
'Artist Display Name'.freeze
SUFFIX =
'Artist Suffix'.freeze
BEGIN_DATE =
'Artist Begin Date'.freeze
END_DATE =
'Artist End Date'.freeze
OBJECT_BEGIN_DATE =
'Object Begin Date'.freeze
OBJECT_END_DATE =
'Object End Date'.freeze
ROLE =
'Artist Role'.freeze
BIO =
'Artist Display Bio'.freeze
CLASSIFICATION =
'Classification'.freeze
PUBLIC_DOMAIN =
'Is Public Domain'.freeze
DEPARTMENT =
'Department'.freeze
REPOSITORY =
'Repository'.freeze

Instance Method Summary collapse

Instance Method Details

#artist_date_range(row) ⇒ Object


35
36
37
# File 'lib/macros/met_csv.rb', line 35

def artist_date_range(row)
  [row[BEGIN_DATE], row[END_DATE]].select(&:present?).join(' - ')
end

#artist_role_bio(row) ⇒ Object


39
40
41
42
43
44
# File 'lib/macros/met_csv.rb', line 39

def artist_role_bio(row)
  role = [row[ROLE], row[BIO]].select(&:present?).join(' ; ')
  artist_info = artist_date_range(row)
  artist_info += " (#{role})" if role.present?
  artist_info
end

#data_providerObject

This overrides the dlme macro of the same name


68
69
70
71
72
# File 'lib/macros/met_csv.rb', line 68

def data_provider
  lambda do |row, accumulator, _context|
    accumulator << [row['Department'], row['Repository']].select(&:present?).join(', ').presence
  end
end

#edm_typeObject


54
55
56
57
58
# File 'lib/macros/met_csv.rb', line 54

def edm_type
  lambda do |row, accumulator, _context|
    accumulator << 'Image' if row[CLASSIFICATION].present?
  end
end

#generate_creatorObject


29
30
31
32
33
# File 'lib/macros/met_csv.rb', line 29

def generate_creator
  lambda do |row, accumulator, _context|
    accumulator << [row[DISPLAY_NAME], row[SUFFIX], artist_role_bio(row)].select(&:present?).join(', ').presence
  end
end

#generate_object_dateObject


46
47
48
49
50
51
52
# File 'lib/macros/met_csv.rb', line 46

def generate_object_date
  lambda do |row, accumulator, _context|
    object_date = row[OBJECT_BEGIN_DATE] unless row[OBJECT_BEGIN_DATE].to_s.empty?
    object_date = "#{object_date} - #{row[OBJECT_END_DATE]}" unless row[OBJECT_END_DATE].to_s.empty?
    accumulator << object_date
  end
end

#met_thumbnailObject


21
22
23
24
25
26
27
# File 'lib/macros/met_csv.rb', line 21

def met_thumbnail
  lambda do |_record, accumulator, context|
    ident = context.output_hash['id'].first.sub(/^met_/, '')
    thumbnail = MetThumbnailFetcher.fetch(ident)
    accumulator << transform_values(context, 'wr_id' => literal(thumbnail)) if thumbnail
  end
end

#public_domainObject


60
61
62
63
64
65
# File 'lib/macros/met_csv.rb', line 60

def public_domain
  lambda do |row, accumulator, _context|
    accumulator << 'Public Domain' if row[PUBLIC_DOMAIN] == 'True'
    accumulator << 'Not Public Domain' if row[PUBLIC_DOMAIN] == 'False'
  end
end