Class: Kiba::Extend::Sources::Marc

Inherits:
Object
  • Object
show all
Extended by:
Sourceable
Defined in:
lib/kiba/extend/sources/marc.rb

Overview

Note:

Only transforms in the Kiba::Extend::Transforms::Marc namespace can initially be used on records from this source

Note:

The class name is Marc instead of MARC because the ruby-marc gem already has the MARC namespace

Given a binary MARC file containing one or more MARC records, yields one MARC record at a time, for processing.

This is just a simple wrapper around ruby-marc’s MARC::Reader :each method. See that class’ documentation at https://github.com/ruby-marc/ruby-marc/blob/main/lib/marc/reader.rb for more details about args that can be passed in to deal with character encoding.

See File Registry Entry documentation page for more details on how to set up a Marc source in a project.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Sourceable

is_source?

Methods included from Registry::Fileable

#default_args, #default_file_options, #labeled_options, #options_key, #path_key, #requires_path?

Constructor Details

#initialize(filename:, args: nil) ⇒ Marc

Returns a new instance of Marc.

Parameters:

  • filename (String)

    path to MARC binary file (.mrc, .dat, etc.)

  • args (Hash) (defaults to: nil)

    of MARC::Reader optional keyword arguments. See documentation at: https://github.com/ruby-marc/ruby-marc/blob/main/lib/marc/reader.rb for more details



51
52
53
54
55
56
57
# File 'lib/kiba/extend/sources/marc.rb', line 51

def initialize(filename:, args: nil)
  @args = if args
    [filename, args]
  else
    [filename]
  end
end

Class Method Details

.default_file_optionsObject



29
30
31
# File 'lib/kiba/extend/sources/marc.rb', line 29

def default_file_options
  nil
end

.options_keyObject



33
34
35
# File 'lib/kiba/extend/sources/marc.rb', line 33

def options_key
  :args
end

.path_keyObject



37
38
39
# File 'lib/kiba/extend/sources/marc.rb', line 37

def path_key
  :filename
end

.requires_path?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/kiba/extend/sources/marc.rb', line 41

def requires_path?
  true
end

Instance Method Details

#eachObject



59
60
61
62
63
# File 'lib/kiba/extend/sources/marc.rb', line 59

def each
  MARC::Reader.new(*args).each do |record|
    yield(record)
  end
end