Class: Kiba::Extend::Transforms::Marc::Extract245Title

Inherits:
Object
  • Object
show all
Defined in:
lib/kiba/extend/transforms/marc/extract_245_title.rb

Overview

Extract title fields from 245 (and/or linked 880) fields, along with :marcid value

Examples:

Just 245

# 245 13 $a Un sextuor pour piano et cordes en mi bémol majeur
# $h [sound recording] ; $b Divertimento sur des thémes de la
# Somnanbula de Bellini ; Sérénade sur des thémes d'Anna Bolena de
# Donizetti / $c Mikhail Glinka.
rec = get_marc_record(index: 9)
xform = Marc::Extract245Title.new
result = xform.process(rec)[:title]
expected = "Un sextuor pour piano et cordes en mi bémol majeur ; Divertimento sur des thémes de la Somnanbula de Bellini ; Sérénade sur des thémes d'Anna Bolena de Donizetti"
expect(result).to eq(expected)

Deleting non-filing characters

# Same MARC data as above example
rec = get_marc_record(index: 9)
xform = Marc::Extract245Title.new(delete_non_filing: true)
result = xform.process(rec)[:title]
expected = "sextuor pour piano et cordes en mi bémol majeur ; Divertimento sur des thémes de la Somnanbula de Bellini ; Sérénade sur des thémes d'Anna Bolena de Donizetti"
expect(result).to eq(expected)

Deleting non-filing characters and upcasing first char

# Same MARC data as above example
rec = get_marc_record(index: 9)
xform = Marc::Extract245Title.new(
  delete_non_filing: true,
  upcase_first_filing_char: true
)
result = xform.process(rec)[:title]
expected = "Sextuor pour piano et cordes en mi bémol majeur ; Divertimento sur des thémes de la Somnanbula de Bellini ; Sérénade sur des thémes d'Anna Bolena de Donizetti"
expect(result).to eq(expected)

880 and Preferring vernacular

# 245 10 $6 880-02 $a Jidō shinri hen / $c Nihon Ryōshin Saikyōiku
#   Kyōkai hen.
# 880 10 $6 245-02 $a 兒童心理篇 / $c 日本兩親再教育協會編.
rec = get_marc_record(index: 6)
xform = Marc::Extract245Title.new
result = xform.process(rec)[:title]
expected = '兒童心理篇'
expect(result).to eq(expected)

880 and not preferring vernacular

# Same MARC data as above example
rec = get_marc_record(index: 6)
Kiba::Extend::Marc.config.prefer_vernacular = false
xform = Marc::Extract245Title.new
result = xform.process(rec)[:title]
Kiba::Extend::Marc.reset_config
expected = 'Jidō shinri hen|兒童心理篇'
expect(result).to eq(expected)

Since:

  • 3.3.0

Instance Method Summary collapse

Constructor Details

#initialize(id_target: Kiba::Extend::Marc.id_target_field, title_target: :title, title_subfields: Kiba::Extend::Marc.title_part_subfields, delim: Kiba::Extend.delim, delete_non_filing: false, upcase_first_filing_char: false) ⇒ Extract245Title

Returns a new instance of Extract245Title.

Parameters:

  • id_target (Symbol) (defaults to: Kiba::Extend::Marc.id_target_field)

    row field into which id value will be written

  • title_target (Symbol) (defaults to: :title)

    row field into which title value will be written

  • title_subfields (Array<String>) (defaults to: Kiba::Extend::Marc.title_part_subfields)

    subfields of 245 to extract as part of title value. NOTE: Any space-punctuation-space? at the end of a $h is retained as part of title if $h itself is not included as part of title

  • delim (String) (defaults to: Kiba::Extend.delim)

    used when joining values from multiple fields

  • delete_non_filing (Boolean) (defaults to: false)

    if true, removes nonfiling characters as specified in 245 2nd indicator

  • upcase_first_filing_char (Boolean) (defaults to: false)

    if true, upcases the first character of each title after non-filing characters are deleted. Has no effect if you are not deleting non-filing chars.

Since:

  • 3.3.0



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/kiba/extend/transforms/marc/extract_245_title.rb', line 76

def initialize(id_target: Kiba::Extend::Marc.id_target_field,
  title_target: :title,
  title_subfields:
  Kiba::Extend::Marc.title_part_subfields,
  delim: Kiba::Extend.delim,
  delete_non_filing: false,
  upcase_first_filing_char: false)
  @id_target = id_target
  @title_target = title_target
  @title_subfields = title_subfields
  @delim = delim
  @delete_non_filing = delete_non_filing
  @upcase_first_filing_char = upcase_first_filing_char
  @idextractor = Kiba::Extend::Utils::MarcIdExtractor.new
end

Instance Method Details

#process(record) ⇒ Hash{ Symbol => String, nil }

Parameters:

  • record (MARC::Record)

Returns:

  • (Hash{ Symbol => String, nil })

Since:

  • 3.3.0



94
95
96
97
98
99
# File 'lib/kiba/extend/transforms/marc/extract_245_title.rb', line 94

def process(record)
  id = idextractor.call(record)
  row = {id_target => id}
  row[title_target] = title_value(record)
  row
end