diff --git a/docker-compose.yml b/docker-compose.yml index 5769116..9316df5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,19 +31,6 @@ services: - solr-sdr-catalog - mariadb - test-persist: - build: . - volumes: - - .:/usr/src/app - - gem_cache:/gems - command: bash -c "bin/wait-for solr-sdr-catalog:9033 mariadb:3306" - environment: - SOLR_URL: http://solr-sdr-catalog:9033/solr/catalog - RIGHTS_DATABASE_CONNECTION_STRING: "mysql2://ht_rights:ht_rights@mariadb/ht" - depends_on: - - solr-sdr-catalog - - mariadb - solr-sdr-catalog: image: ghcr.io/hathitrust/catalog-solr-sample ports: diff --git a/lib/oai_solr/basic_marc_extractor.rb b/lib/oai_solr/basic_marc_extractor.rb index 73e87e1..ca4a69b 100644 --- a/lib/oai_solr/basic_marc_extractor.rb +++ b/lib/oai_solr/basic_marc_extractor.rb @@ -71,8 +71,8 @@ def values(rec) # merge into one set; the ranges we handle separately for efficiency (no sense in # turning '600'..'699' into an array) def set_interesting_tags! - @interesting_single_tags = Set.new - @interesting_ranges = Set.new + @interesting_single_tags = ::Set.new + @interesting_ranges = ::Set.new @single_extractors.map(&:computed_tags).each do |tags| case tags when Range diff --git a/lib/oai_solr/basic_marc_single_extractor.rb b/lib/oai_solr/basic_marc_single_extractor.rb index 6081f60..97775c9 100644 --- a/lib/oai_solr/basic_marc_single_extractor.rb +++ b/lib/oai_solr/basic_marc_single_extractor.rb @@ -110,7 +110,7 @@ def tag_matcher(tags_to_match) @computed_tags = tags_to_match ->(t) { @computed_tags.cover?(t) } else - raise "Illegal argumrnt '#{tags_to_match.inspect}'" + raise "Illegal argument '#{tags_to_match.inspect}'" end end diff --git a/lib/oai_solr/dublin_core_crosswalk.rb b/lib/oai_solr/dublin_core_crosswalk.rb index 0f0a51b..114c23d 100644 --- a/lib/oai_solr/dublin_core_crosswalk.rb +++ b/lib/oai_solr/dublin_core_crosswalk.rb @@ -82,31 +82,17 @@ class DublinCoreCrosswalk # type -- see below } - # Build the instance that will do the data extraction based on the mappings - # in MAPPINGS. - def initialize - MAPPINGS.each_pair do |key, spec_pairs| - define_singleton_method(key.to_sym, basic_marc_extractor_proc(spec_pairs)) - end + MAPPINGS.each do |key, spec_pairs| + bme = BasicMARCExtractor.from_pairs(spec_pairs) + define_method(key.to_sym, ->(rec) { bme.values(rec) }) end + # If it's necessary to add a field that does not have an identically-named + # accessor, or is not in MAPPINGS, some adjustment may be necessary, def full_map(rec) - { - contributor: contributor(rec), - coverage: coverage(rec), - date: date(rec), - description: description(rec), - format: self.format(rec), # need self to avoid keyword conflict - identifier: identifier(rec), - language: language(rec), - publisher: publisher(rec), - relation: relation(rec), - rights: rights(rec), - source: source(rec), - subject: subject(rec), - title: title(rec), - type: type(rec) - }.reject { |k, v| v.empty? } + fields = MAPPINGS.keys + %i(type date) + Hash[fields.map {|field| [ field, self.send(field, rec)] }] + .reject { |k, v| v.empty? } end # Get the best date possible, looking for four digits in the 008, then @@ -138,11 +124,6 @@ def type(rec) private - def basic_marc_extractor_proc(pairs) - bme = BasicMARCExtractor.from_pairs(pairs) - ->(rec) { bme.values(rec) } - end - def date_008(rec) rec["008"].value[7..10] end