Skip to content

Commit

Permalink
Add an isbn attribute to the MarcRecord class and add the MARC 020 or…
Browse files Browse the repository at this point in the history
… to it.
  • Loading branch information
jkeck committed Nov 21, 2020
1 parent d246c6e commit 9b9ec52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
9 changes: 8 additions & 1 deletion app/models/upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,19 @@ def extract_marc_record_metadata(file, service)
marc001: record['001']&.value,
file_id: file.id,
upload_id: id,
marc: record
marc: record,
isbn: record_isbn(record)
)

out.checksum ||= Digest::MD5.hexdigest(record.to_xml.to_s)

yield out
end
end

def record_isbn(record)
marc020 = record['020'] || {}

(marc020['a'] || marc020['z'])&.[](/^x?\d+/)
end
end
6 changes: 6 additions & 0 deletions db/migrate/20201120180608_add_isbn_to_marc_record.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddIsbnToMarcRecord < ActiveRecord::Migration[6.0]
def change
add_column :marc_records, :isbn, :string
add_index :marc_records, :isbn
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2020_11_19_191233) do
ActiveRecord::Schema.define(version: 2020_11_20_180608) do

create_table "active_storage_attachments", force: :cascade do |t|
t.string "name", null: false
Expand Down Expand Up @@ -91,8 +91,10 @@
t.bigint "length"
t.bigint "index"
t.string "checksum"
t.string "isbn"
t.index ["file_id", "marc001"], name: "index_marc_records_on_file_id_and_marc001"
t.index ["file_id"], name: "index_marc_records_on_file_id"
t.index ["isbn"], name: "index_marc_records_on_isbn"
t.index ["upload_id", "marc001"], name: "index_marc_records_on_upload_id_and_marc001"
t.index ["upload_id"], name: "index_marc_records_on_upload_id"
end
Expand Down

0 comments on commit 9b9ec52

Please sign in to comment.