Module: DS::Extractor::DsCsvExtractor::ClassMethods

Included in:
DS::Extractor::DsCsvExtractor
Defined in:
lib/ds/extractor/ds_csv_extractor.rb

Instance Method Summary collapse

Instance Method Details

#balanced_titles?(as_recorded_titles, uniform_titles) ⇒ Boolean

Return true if the as_recorded and uniform titles are of equal length.

Parameters:

  • as_recorded_titles (Array<String>)
  • uniform_titles (Array<String>)

Returns:

  • (Boolean)


416
417
418
419
420
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 416

def balanced_titles? as_recorded_titles, uniform_titles
  return true if uniform_titles.blank?

  as_recorded_titles.size == uniform_titles.size
end

#extract_acknowledgments(record) ⇒ Array

Extracts acknowledgments from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract acknowledgments from

Returns:

  • (Array)

    the extracted acknowledgments



564
565
566
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 564

def extract_acknowledgments record
  extract_values_for property: :acknowledgments, record: record
end

#extract_all_subjects(record) ⇒ Array<DS::Extractor::Subject>

Extracts all subjects from the given record, including subjects and named subjects.

Parameters:

  • record (CSV::Row)

    the record to extract all subjects from

Returns:



520
521
522
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 520

def extract_all_subjects record
  extract_subjects(record) + extract_named_subjects(record)
end

#extract_all_subjects_as_recorded(record) ⇒ Array<String>

Extracts all subjects as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract all subjects from

Returns:

  • (Array<String>)

    the extracted all subjects as recorded



512
513
514
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 512

def extract_all_subjects_as_recorded record
  extract_all_subjects(record).map &:as_recorded
end

#extract_artists(record) ⇒ Array<String>

Extracts artists from the given record using the specified type and role.

Parameters:

  • record (CSV::Row)

    the record to extract artists from

Returns:

  • (Array<String>)

    the extracted artists



247
248
249
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 247

def extract_artists record
  extract_names(record, :artists_as_recorded, 'artist')
end

#extract_artists_as_recorded(record) ⇒ Array<String>

Extracts artists as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract artists from

Returns:

  • (Array<String>)

    the extracted artists as recorded



231
232
233
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 231

def extract_artists_as_recorded record
  extract_artists(record).map &:as_recorded
end

#extract_artists_as_recorded_agr(record) ⇒ Array<String>

Extracts artists as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract artists from

Returns:

  • (Array<String>)

    the extracted artists as recorded with vernacular form



239
240
241
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 239

def extract_artists_as_recorded_agr record
  extract_artists(record).map &:vernacular
end

#extract_associated_agents(record) ⇒ Array<String>

Note:

Method to fulfill DS::Extractor contract; returns an empty array

Extracts associated agents from the given record.

Parameters:

  • record (CSV::Row)

    the record

Returns:

  • (Array<String>)

    an empty array



305
306
307
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 305

def extract_associated_agents record
  []
end

#extract_authors(record) ⇒ Array<String>

Extracts authors from the given record using the specified type and role.

Parameters:

  • record (CSV::Row)

    the record to extract authors from

Returns:

  • (Array<String>)

    the extracted authors



223
224
225
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 223

def extract_authors record
  extract_names(record, :authors_as_recorded, 'author')
end

#extract_authors_as_recorded(record) ⇒ Array<String>

Extracts authors as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract authors from

Returns:

  • (Array<String>)

    the extracted authors as recorded



207
208
209
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 207

def extract_authors_as_recorded record
  extract_authors(record).map &:as_recorded
end

#extract_authors_as_recorded_agr(record) ⇒ Array<String>

Extracts authors as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract authors from

Returns:

  • (Array<String>)

    the extracted authors as recorded with vernacular form



215
216
217
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 215

def extract_authors_as_recorded_agr record
  extract_authors(record).map &:vernacular
end

#extract_cataloging_convention(record) ⇒ String

Extracts the cataloging convention value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the cataloging convention from

Returns:

  • (String)

    the extracted cataloging convention value



76
77
78
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 76

def extract_cataloging_convention record
  extract_values_for(property: :cataloging_convention, record: record).first
end

#extract_date_range(record, range_sep:) ⇒ Array<String>

Extracts the date range from the given record using the specified separator.

Parameters:

  • record (CSV::Row)

    the record to extract the date range from

  • range_sep (String)

    the separator to be used in the date range

Returns:

  • (Array<String>)

    the extracted date range



145
146
147
148
149
150
151
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 145

def extract_date_range record, range_sep:
  start_date = extract_production_date_start record
  end_date   = extract_production_date_end record
  range = [start_date, end_date].select(&:present?)
  return [] if range.blank?
  [range.join(range_sep)]
end

#extract_dated(record) ⇒ Boolean

Extracts the dated value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the dated value from

Returns:

  • (Boolean)

    true if the dated value is ‘true’, false otherwise



173
174
175
176
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 173

def extract_dated record
  dated = extract_values_for(property: :dated, record: record)
  return true if dated.join.strip.downcase == 'true'
end

#extract_dimensions(record) ⇒ Array<String>

Extracts the dimensions from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the dimensions from

Returns:

  • (Array<String>)

    the extracted dimensions



199
200
201
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 199

def extract_dimensions record
  extract_values_for property: :dimensions, record: record
end

#extract_dsid(record) ⇒ String

Extracts the DSID value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the DSID from

Returns:

  • (String)

    the extracted DSID value



60
61
62
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 60

def extract_dsid record
  [extract_values_for(property: :ds_id, record: record)].flatten.first
end

#extract_former_owners(record) ⇒ Array<String>

Extracts former owners from the given record using the specified type and role.

Parameters:

  • record (CSV::Row)

    the record to extract former owners from

Returns:

  • (Array<String>)

    the extracted former owners



295
296
297
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 295

def extract_former_owners record
  extract_names(record, :former_owners_as_recorded, 'former owner')
end

#extract_former_owners_as_recorded(record) ⇒ Array<String>

Extracts former owners as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract former owners from

Returns:

  • (Array<String>)

    the extracted former owners as recorded



279
280
281
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 279

def extract_former_owners_as_recorded record
  extract_former_owners(record).map &:as_recorded
end

#extract_former_owners_as_recorded_agr(record) ⇒ Array<String>

Extracts former owners as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract former owners from

Returns:

  • (Array<String>)

    the extracted former owners as recorded with vernacular form



287
288
289
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 287

def extract_former_owners_as_recorded_agr record
  extract_former_owners(record).map &:vernacular
end

#extract_fragment_num_disambiguator(record) ⇒ String

Extracts the fragment number or disambiguator value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the fragment number or disambiguator from

Returns:

  • (String)

    the extracted fragment number or disambiguator value



108
109
110
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 108

def extract_fragment_num_disambiguator record
  extract_values_for(property: :fragment_num_disambiguator, record: record).first
end

#extract_genres(record) ⇒ Array<DS::Extractor::Genre>

Extracts genres from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract genres from

Returns:



496
497
498
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 496

def extract_genres record
  extract_terms record, :genres_as_recorded, DS::Extractor::Genre, vocab: 'ds-genre'
end

#extract_genres_as_recorded(record) ⇒ Array<String>

Extracts genres as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract genres from

Returns:

  • (Array<String>)

    the extracted genres as recorded



488
489
490
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 488

def extract_genres_as_recorded record
  extract_genres(record).map &:as_recorded
end

#extract_holding_institution_as_recorded(record) ⇒ String

Extracts the cataloging convention value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the cataloging convention from

Returns:

  • (String)

    the extracted cataloging convention value



84
85
86
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 84

def extract_holding_institution_as_recorded record
  extract_values_for(property: :holding_institution_as_recorded, record: record).first
end

#extract_holding_institution_id_number(record) ⇒ String

Extracts the institutional identifier (e.g., BibID) from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the cataloging convention from

Returns:

  • (String)

    the institutional identifier for the manuscript



92
93
94
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 92

def extract_holding_institution_id_number record
  extract_values_for(property: :holding_institution_id_number, record: record).first
end

#extract_holding_institution_shelfmark(record) ⇒ String

Extracts the holding institution shelfmark from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the holding institution shelfmark from

Returns:

  • (String)

    the extracted holding institution shelfmark value



100
101
102
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 100

def extract_holding_institution_shelfmark record
  extract_values_for(property: :holding_institution_shelfmark, record: record).first
end

#extract_languages(record) ⇒ Array<DS::Extractor::Language>

Extracts languages from the given record using the specified type and role.

Parameters:

  • record (CSV::Row)

    the record to extract languages from

Returns:



321
322
323
324
325
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 321

def extract_languages record
  extract_values_for(property: :languages_as_recorded, record: record).map { |lang|
    DS::Extractor::Language.new as_recorded: lang
  }
end

#extract_languages_as_recorded(record) ⇒ Array<String>

Extracts languages as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract languages from

Returns:

  • (Array<String>)

    the extracted languages as recorded



313
314
315
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 313

def extract_languages_as_recorded record
  extract_languages(record).map &:as_recorded
end

Extracts the link to the holding institution record from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the link from

Returns:

  • (String)

    the extracted link to the holding institution record



116
117
118
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 116

def extract_link_to_holding_institution_record record
  extract_values_for(property: :link_to_holding_institution_record, record: record).first
end

Extracts the link to the IIIF manifest from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the link from

Returns:

  • (String)

    the extracted link to the IIIF manifest



124
125
126
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 124

def extract_link_to_iiif_manifest record
  extract_values_for(property: :link_to_iiif_manifest, record: record).first
end

#extract_material_as_recorded(record) ⇒ String?

Extracts material as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract material from

Returns:

  • (String, nil)

    the extracted material as recorded



331
332
333
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 331

def extract_material_as_recorded record
  extract_materials(record).map(&:as_recorded).join '|'
end

#extract_materials(record) ⇒ Array<DS::Extractor::Material>

Extracts materials from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract materials from

Returns:



339
340
341
342
343
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 339

def extract_materials record
  extract_values_for(property: :material_as_recorded, record: record).map { |as_recorded|
    DS::Extractor::Material.new as_recorded: as_recorded
  }
end

#extract_named_subjects(record) ⇒ Array<DS::Extractor::Subject>

Extracts named subjects from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract named subjects from

Returns:



544
545
546
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 544

def extract_named_subjects record
  extract_terms record, :named_subjects_as_recorded, DS::Extractor::Subject, vocab: 'ds-subject'
end

#extract_named_subjects_as_recorded(record) ⇒ Array<String>

Extracts named subjects as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract named subjects from

Returns:

  • (Array<String>)

    the extracted named subjects as recorded



536
537
538
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 536

def extract_named_subjects_as_recorded record
  extract_named_subjects(record).map &:as_recorded
end

#extract_names(record, property, role) ⇒ Array<DS::Extractor::Name>

Return names as an array DS::Extractor::Name instances. Name as recorded and vernacular values are in single columns:

Author Name(s)
An author;;An author in original script|Another author

Names are divided by pipe characters and as recorded and vernacular forms of a name are separated by double semicolons: ;;.

Parameters:

  • record (CSV::Row)

    a CSV row with headers

  • property (Symbol)

    a valid property name; e.g., :artist_as_recorded

  • role (String)

    the name role; e.g., artist

Returns:



458
459
460
461
462
463
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 458

def extract_names record, property, role
  extract_values_for(property: property, record: record).map { |name|
    as_recorded, vernacular = name.to_s.split ';;', 2
    DS::Extractor::Name.new as_recorded: as_recorded, vernacular: vernacular, role: role
  }
end

#extract_notes(record) ⇒ Array<String>

Extracts notes from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract notes from

Returns:

  • (Array<String>)

    the extracted notes



666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 666

def extract_notes record
  notes = COLUMN_MAPPINGS[:notes].filter_map { |header|
    vals = extract_values_for_header header:  header, record: record
    next unless vals

    case header
    when /^(Note|Physical description)/i
      vals
    when /^Provenance/
      vals.map { |v| "Provenance: #{v}" }
    else
      vals.map { |v| "#{header}: #{v}" }
    end
  }.flatten.map { |s| mark_long s }
  notes
end

#extract_physical_description(record) ⇒ Array<String>

TODO:

implement extract_names

Extracts the physical description from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the physical description from

Returns:

  • (Array<String>)

    the extracted physical description



183
184
185
186
187
188
189
190
191
192
193
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 183

def extract_physical_description record
  extent     = extract_values_for property: :extent, record: record
  material   = extract_values_for property: :material_as_recorded, record: record
  dimensions = extract_dimensions record
  desc       = [extent, material, dimensions].flatten

  # return an empty array if no values are present
  return [] unless desc.any?(&:present?)

  ["Extent: #{desc.join '; '}"]
end

#extract_places(record, property = :production_places_as_recorded) ⇒ Array<DS::Extractor::Place>

Extracts places from the given record using the specified property.

Parameters:

  • property (Symbol) (defaults to: :production_places_as_recorded)

    the property to extract places from the record

  • record (CSV::Row)

    the record to extract places from

Returns:



478
479
480
481
482
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 478

def extract_places record, property = :production_places_as_recorded
  extract_values_for(property: property, record: record).map { |place|
    DS::Extractor::Place.new as_recorded: place
  }
end

#extract_production_date_as_recorded(record) ⇒ Array<String>

Extracts the production date as recorded value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the production date from

Returns:

  • (Array<String>)

    the extracted production dates



132
133
134
135
136
137
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 132

def extract_production_date_as_recorded record
  dar = extract_values_for(property: :production_date_as_recorded, record: record)
  return dar if dar.present?

  extract_date_range record, range_sep: '-'
end

#extract_production_date_end(record) ⇒ String

Extracts the production date end value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the production date end from

Returns:

  • (String)

    the extracted production date end value



165
166
167
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 165

def extract_production_date_end record
  extract_values_for(property: :production_date_end, record: record).first
end

#extract_production_date_start(record) ⇒ String

Extracts the production date start value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the production date start from

Returns:

  • (String)

    the extracted production date start value



157
158
159
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 157

def extract_production_date_start record
  extract_values_for(property: :production_date_start, record: record).first
end

#extract_production_places_as_recorded(record) ⇒ Array<String>

Extracts production places as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract production places from

Returns:

  • (Array<String>)

    the extracted production places as recorded



469
470
471
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 469

def extract_production_places_as_recorded record
  extract_places(record, :production_places_as_recorded).map &:as_recorded
end

#extract_recon_genres(record) ⇒ Array

Extracts reconstructed genres from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract reconstructed genres from

Returns:

  • (Array)

    the extracted reconstructed genres



596
597
598
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 596

def extract_recon_genres record
  extract_genres(record).map &:to_a
end

#extract_recon_names(record) ⇒ Object



601
602
603
604
605
606
607
608
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 601

def extract_recon_names record
  names = []
  names += extract_names(record, :authors_as_recorded, 'author').map(&:to_a)
  names += extract_names(record, :artists_as_recorded, 'artist').map(&:to_a)
  names += extract_names(record, :scribes_as_recorded, 'scribe').map(&:to_a)
  names += extract_names(record, :former_owners_as_recorded, 'former owner').map(&:to_a)
  names
end

#extract_recon_places(record) ⇒ Array

Extracts reconstructed places from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract reconstructed places from

Returns:

  • (Array)

    the extracted reconstructed places



572
573
574
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 572

def extract_recon_places record
  extract_places(record, :production_places_as_recorded).map &:to_a
end

#extract_recon_subjects(record) ⇒ Array

Extracts reconstructed subjects from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract reconstructed subjects from

Returns:

  • (Array)

    the extracted reconstructed subjects



588
589
590
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 588

def extract_recon_subjects record
  extract_all_subjects(record).map &:to_a
end

#extract_recon_titles(record) ⇒ Array

Extracts reconstructed titles from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract reconstructed titles from

Returns:

  • (Array)

    the extracted reconstructed titles



580
581
582
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 580

def extract_recon_titles record
  extract_titles(record).map &:to_a
end

#extract_scribes(record) ⇒ Array<String>

Extracts scribes from the given record using the specified type and role.

Parameters:

  • record (CSV::Row)

    the record to extract scribes from

Returns:

  • (Array<String>)

    the extracted scribes



271
272
273
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 271

def extract_scribes record
  extract_names(record, :scribes_as_recorded, 'scribe')
end

#extract_scribes_as_recorded(record) ⇒ Array<String>

Extracts scribes as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract scribes from

Returns:

  • (Array<String>)

    the extracted scribes as recorded



255
256
257
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 255

def extract_scribes_as_recorded record
  extract_scribes(record).map &:as_recorded
end

#extract_scribes_as_recorded_agr(record) ⇒ Array<String>

Extracts scribes as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract scribes from

Returns:

  • (Array<String>)

    the extracted scribes as recorded with vernacular form



263
264
265
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 263

def extract_scribes_as_recorded_agr record
  extract_scribes(record).map &:vernacular
end

#extract_source_type(record) ⇒ String

Extracts the source type value from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract the source type from

Returns:

  • (String)

    the extracted source type value



68
69
70
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 68

def extract_source_type record
  extract_values_for(property: :source_type, record: record).first
end

#extract_subjects(record) ⇒ Array<DS::Extractor::Subject>

Extracts subjects from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract subjects from

Returns:



528
529
530
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 528

def extract_subjects record
  extract_terms record, :subjects_as_recorded, DS::Extractor::Subject, vocab: 'ds-subject'
end

#extract_subjects_as_recorded(record) ⇒ Array<String>

Extracts subjects as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract subjects from

Returns:

  • (Array<String>)

    the extracted subjects as recorded



504
505
506
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 504

def extract_subjects_as_recorded record
  extract_subjects(record).map &:as_recorded
end

#extract_terms(record, property, term_type, vocab: nil) ⇒ Array<term_type>

Extracts terms of a specific type from the given record using the specified property.

Parameters:

  • record (CSV::Row)

    the record to extract terms from

  • property (Symbol)

    the property to extract terms from the record

  • term_type (Class)

    the type of terms to extract

Returns:

  • (Array<term_type>)

    the extracted terms



554
555
556
557
558
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 554

def extract_terms record, property, term_type, vocab: nil
  extract_values_for(property: property, record: record).map { |term|
    term_type.new as_recorded: term, vocab: vocab
  }
end

#extract_titles(record) ⇒ Array<DS::Extractor::Title>

Return titles as an array of DS::Extractor::Title instances. Title as recorded and vernacular values are in single columns:

Uniform Title(s)
Al-Hajj;;الجزء التاسع

Titles are divided by pipe characters and as recorded and vernacular forms of a title are separated by double semicolons: ;;.

Parameters:

  • record (CSV::Row)

    a CSV row with headers

Returns:



390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 390

def extract_titles record
  as_recorded_titles = extract_values_for(property: :titles_as_recorded, record: record)
  uniform_titles     = extract_values_for(property: :uniform_titles_as_recorded, record: record)
  as_recorded_titles << '' if as_recorded_titles.blank?

  unless balanced_titles? as_recorded_titles, uniform_titles
    raise ArgumentError, "Unbalanced number of titles and uniform titles (titles: #{as_recorded_titles.inspect}, uniform titles: #{uniform_titles.inspect})"
  end

  as_recorded_titles.zip(uniform_titles).map { |as_rec, uniform|
    as_recorded, vernacular                 = as_rec.split ';;', 2
    uniform_title, uniform_title_vernacular = uniform.to_s.split ';;', 2
    DS::Extractor::Title.new(
      as_recorded:              as_recorded,
      vernacular:               vernacular,
      uniform_title:            uniform_title,
      uniform_title_vernacular: uniform_title_vernacular
    )
  }
end

#extract_titles_as_recorded(record) ⇒ Array<String>

Extracts titles as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract titles from

Returns:

  • (Array<String>)

    the extracted titles as recorded



349
350
351
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 349

def extract_titles_as_recorded record
  extract_titles(record).map &:as_recorded
end

#extract_titles_as_recorded_agr(record) ⇒ Array<String>

Extracts titles as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract titles from

Returns:

  • (Array<String>)

    the extracted titles as recorded with vernacular form



357
358
359
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 357

def extract_titles_as_recorded_agr record
  extract_titles(record).map &:vernacular
end

#extract_uniform_titles(record) ⇒ Array<DS::Extractor::Title>

Note: BaseTerm implementations require as_recorded; for DS CSV we don’t assume that the Title(s) and Uniform Titles(s) are paralleled so they’re handled separately.

@todo: Find out whether we should enforce that Titles and

Uniform Titles be evenly paired.

Extracts uniform titles from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract uniform titles from

Returns:



433
434
435
436
437
438
439
440
441
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 433

def extract_uniform_titles record
  extract_values_for(property: :uniform_titles_as_recorded, record: record).map { |title|
    as_recorded, vernacular = title.to_s.split ';;', 2
    # BaseTerm implementations require +as_recorded+; for DS CSV
    # we don't assume that the Title(s) and Uniform Titles(s)
    # are paralleled so there handled separately
    DS::Extractor::Title.new as_recorded: nil, uniform_title: as_recorded, uniform_title_vernacular: vernacular
  }
end

#extract_uniform_titles_as_recorded(record) ⇒ Array<String>

Extracts uniform titles as recorded from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract uniform titles from

Returns:

  • (Array<String>)

    the extracted uniform titles as recorded



365
366
367
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 365

def extract_uniform_titles_as_recorded record
  extract_uniform_titles(record).map &:uniform_title
end

#extract_uniform_titles_as_recorded_agr(record) ⇒ Array<String>

Extracts uniform titles as recorded with vernacular form from the given record.

Parameters:

  • record (CSV::Row)

    the record to extract uniform titles from

Returns:

  • (Array<String>)

    the extracted uniform titles as recorded with vernacular form



373
374
375
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 373

def extract_uniform_titles_as_recorded_agr record
  extract_uniform_titles(record).map &:uniform_title_vernacular
end

#extract_values_for(property:, record:) ⇒ Array

Extracts values for a specific property from a record.

Parameters:

  • property (Symbol)

    the property to extract values for

  • record (CSV::Row)

    the record containing the values

Returns:

  • (Array)

    the extracted values



615
616
617
618
619
620
621
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 615

def extract_values_for property:, record:
  raise "Unknown property: #{property}" unless known_property? property
  columns = [COLUMN_MAPPINGS[property.to_sym]].flatten
  columns.filter_map { |header|
    extract_values_for_header header: header, record: record
  }.flatten.map { |s| mark_long s}
end

#extract_values_for_header(header:, record:) ⇒ Array<String>

Extracts the values for a specific header from a record, splitting on ‘|’ and stripping whitespace.

Parameters:

  • record (CSV::Row)

    the record containing the values

  • header (String)

    the header to extract values for

Returns:

  • (Array<String>)

    the extracted values



628
629
630
631
632
633
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 628

def extract_values_for_header header:, record:
  return unless record[header].present?

  # use split -1 to preserve empty values
  record[header].to_s.split('|', -1).map(&:strip)
end

#get_property_name(method_name) ⇒ String?

Determines the property name extracted from the method name.

Parameters:

  • method_name (String)

    the method name to extract the property name from

Returns:

  • (String, nil)

    the extracted property name or nil if not found



657
658
659
660
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 657

def get_property_name method_name
  return unless method_name.to_s =~ /^extract_\w+/
  method_name.to_s.split(/_/, 2).last
end

#known_property?(property) ⇒ Boolean

Determines if a property is known.

Parameters:

  • property (Symbol)

    the property to check if it is known

Returns:

  • (Boolean)

    true if the property is known, false otherwise



649
650
651
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 649

def known_property? property
  COLUMN_MAPPINGS.include? property.to_sym
end

#maps_to_property?(method_name) ⇒ Boolean

Determines if a method name maps to a property.

Parameters:

  • method_name (String)

    the method name to check

Returns:

  • (Boolean)

    true if the method name corresponds to a known property, false otherwise



639
640
641
642
643
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 639

def maps_to_property? method_name
  prop_name = get_property_name method_name
  return unless prop_name
  known_property? prop_name
end

#mark_long(s) ⇒ Object



683
684
685
686
687
688
# File 'lib/ds/extractor/ds_csv_extractor.rb', line 683

def mark_long s
  return s if s.blank?
  return s if s.length <= 400

  "#{LONG_STRING_WARNING}: #{s}"
end