loc_mods 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.adoc +28 -0
- data/lib/loc_mods/geographic_code.rb +2 -0
- data/lib/loc_mods/language_term.rb +2 -0
- data/lib/loc_mods/marc_code_lookup.rb +54 -0
- data/lib/loc_mods/place_term.rb +2 -0
- data/lib/loc_mods/role_term.rb +8 -0
- data/lib/loc_mods/version.rb +1 -1
- data/lib/loc_mods.rb +1 -0
- metadata +11 -10
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 584d5591b5dd0701eb44ba475ebcc2394cf16fd443466241aee6909026e1dee0
|
|
4
|
+
data.tar.gz: 62f09654b28776924e52bb197e246d84b1e488df3aff1311ac17be986c6dc61a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 27f161931994921ef73d8c006217267160606932b177b370da7c9d5626bde4081ddcfcc8c57fde5ee1d0d5d2b0fea118610a006b4ec965b97a7a8985e5d0c9bd
|
|
7
|
+
data.tar.gz: df4a2f1ab1565ab22d64035729581d1765c5d85bc16e6dfe61f3ae29ce80331c8005e10dc5aad26dbed30deb973e7e0105e0fa747c5752c18a14ce1b7b7a3705
|
data/README.adoc
CHANGED
|
@@ -26,6 +26,34 @@ LocMods::Collection.from_xml(File.read("spec/fixtures/record_1.xml"))
|
|
|
26
26
|
LocMods::Collection.from_xml(File.read("reference/allrecords-MODS.xml"))
|
|
27
27
|
----
|
|
28
28
|
|
|
29
|
+
=== MARC 21 code lookup
|
|
30
|
+
|
|
31
|
+
`RoleTerm`, `PlaceTerm`, `LanguageTerm` and `GeographicCode` can look up a
|
|
32
|
+
coded value in the MARC 21 code lists of the
|
|
33
|
+
https://github.com/relaton/loc_marc[`loc_marc`] gem.
|
|
34
|
+
The `authority` attribute selects the code list:
|
|
35
|
+
|
|
36
|
+
|===
|
|
37
|
+
| `authority` | Code list
|
|
38
|
+
|
|
39
|
+
| `marcrelator` | https://www.loc.gov/marc/relators/[MARC Code List for Relators]
|
|
40
|
+
| `marccountry` | https://www.loc.gov/marc/countries/[MARC Code List for Countries]
|
|
41
|
+
| `marcgac` | https://www.loc.gov/marc/geoareas/[MARC Code List for Geographic Areas]
|
|
42
|
+
| `iso639-2b` | https://www.loc.gov/marc/languages/[MARC Code List for Languages]
|
|
43
|
+
|===
|
|
44
|
+
|
|
45
|
+
[source,ruby]
|
|
46
|
+
----
|
|
47
|
+
term = LocMods::RoleTerm.from_xml(
|
|
48
|
+
'<roleTerm xmlns="http://www.loc.gov/mods/v3" type="code" authority="marcrelator">aut</roleTerm>'
|
|
49
|
+
)
|
|
50
|
+
term.code_info # => {code: "aut", description: "Author", deprecated: false}
|
|
51
|
+
term.code_description # => "Author"
|
|
52
|
+
----
|
|
53
|
+
|
|
54
|
+
The methods return `nil` for a `type="text"` term, for an authority without a
|
|
55
|
+
MARC code list, and for an unknown code.
|
|
56
|
+
|
|
29
57
|
=== Command line interface
|
|
30
58
|
|
|
31
59
|
LocMods provides a command-line interface (CLI) for various operations.
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Load only the code lists: the full loc_marc also loads shale and sets
|
|
4
|
+
# the global Shale XML adapter.
|
|
5
|
+
require "loc_marc/codes"
|
|
6
|
+
|
|
7
|
+
module LocMods
|
|
8
|
+
# Looks up a coded term in the MARC 21 code lists from the loc_marc gem.
|
|
9
|
+
#
|
|
10
|
+
# The `authority` attribute selects the code list. Only the authorities in
|
|
11
|
+
# CODE_LISTS are supported. A term with `type="text"`, an unknown authority
|
|
12
|
+
# or an unknown code gives `nil`.
|
|
13
|
+
module MarcCodeLookup
|
|
14
|
+
CODE_LISTS = {
|
|
15
|
+
"marcrelator" => ::LocMarc::Codes::Relator,
|
|
16
|
+
"marccountry" => ::LocMarc::Codes::Country,
|
|
17
|
+
"marcgac" => ::LocMarc::Codes::GeographicArea,
|
|
18
|
+
"iso639-2b" => ::LocMarc::Codes::Language,
|
|
19
|
+
}.freeze
|
|
20
|
+
|
|
21
|
+
# @return [Hash{Symbol=>Object}, nil] a frozen copy of
|
|
22
|
+
# `{ code:, description:, deprecated: }`
|
|
23
|
+
def code_info
|
|
24
|
+
list = marc_code_list
|
|
25
|
+
return unless list && content
|
|
26
|
+
|
|
27
|
+
entry = lookup_marc_code(list, content.strip.downcase)
|
|
28
|
+
entry&.transform_values { |v| v.dup.freeze }&.freeze
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# @return [String, nil] the description of the code
|
|
32
|
+
def code_description
|
|
33
|
+
code_info&.fetch(:description)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
private
|
|
37
|
+
|
|
38
|
+
def marc_code_list
|
|
39
|
+
return if respond_to?(:type) && type == "text"
|
|
40
|
+
return unless authority
|
|
41
|
+
|
|
42
|
+
CODE_LISTS[authority.strip.downcase]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# MARC geographic area codes are padded with hyphens to 7 characters
|
|
46
|
+
# ("n-us---"); the code list stores them without the padding ("n-us").
|
|
47
|
+
def lookup_marc_code(list, code)
|
|
48
|
+
entry = list.lookup(code)
|
|
49
|
+
return entry if entry || list != ::LocMarc::Codes::GeographicArea
|
|
50
|
+
|
|
51
|
+
list.lookup(code.sub(/-+\z/, ""))
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|
data/lib/loc_mods/place_term.rb
CHANGED
data/lib/loc_mods/role_term.rb
CHANGED
|
@@ -4,7 +4,12 @@ require "lutaml/model"
|
|
|
4
4
|
|
|
5
5
|
module LocMods
|
|
6
6
|
class RoleTerm < Lutaml::Model::Serializable
|
|
7
|
+
include MarcCodeLookup
|
|
8
|
+
|
|
7
9
|
attribute :content, :string
|
|
10
|
+
attribute :authority_uri, :string
|
|
11
|
+
attribute :value_uri, :string
|
|
12
|
+
attribute :authority, :string
|
|
8
13
|
attribute :type, :string
|
|
9
14
|
|
|
10
15
|
xml do
|
|
@@ -12,6 +17,9 @@ module LocMods
|
|
|
12
17
|
namespace Namespace
|
|
13
18
|
|
|
14
19
|
map_content to: :content
|
|
20
|
+
map_attribute "authorityURI", to: :authority_uri
|
|
21
|
+
map_attribute "valueURI", to: :value_uri
|
|
22
|
+
map_attribute "authority", to: :authority
|
|
15
23
|
map_attribute "type", to: :type
|
|
16
24
|
end
|
|
17
25
|
end
|
data/lib/loc_mods/version.rb
CHANGED
data/lib/loc_mods.rb
CHANGED
|
@@ -34,6 +34,7 @@ module LocMods
|
|
|
34
34
|
autoload :Language, "loc_mods/language.rb"
|
|
35
35
|
autoload :LanguageTerm, "loc_mods/language_term.rb"
|
|
36
36
|
autoload :Location, "loc_mods/location.rb"
|
|
37
|
+
autoload :MarcCodeLookup, "loc_mods/marc_code_lookup.rb"
|
|
37
38
|
autoload :Name, "loc_mods/name.rb"
|
|
38
39
|
autoload :Namespace, "loc_mods/namespace.rb"
|
|
39
40
|
autoload :NamePart, "loc_mods/name_part.rb"
|
metadata
CHANGED
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: loc_mods
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-11-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: loc_marc
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
17
|
- - "~>"
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: 0.
|
|
19
|
+
version: '0.2'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
24
|
- - "~>"
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: 0.
|
|
26
|
+
version: '0.2'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
|
-
name:
|
|
28
|
+
name: lutaml-model
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
|
-
- - "
|
|
31
|
+
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version:
|
|
33
|
+
version: 0.8.0
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
|
-
- - "
|
|
38
|
+
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version:
|
|
40
|
+
version: 0.8.0
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: thor
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -97,6 +97,7 @@ files:
|
|
|
97
97
|
- lib/loc_mods/language.rb
|
|
98
98
|
- lib/loc_mods/language_term.rb
|
|
99
99
|
- lib/loc_mods/location.rb
|
|
100
|
+
- lib/loc_mods/marc_code_lookup.rb
|
|
100
101
|
- lib/loc_mods/name.rb
|
|
101
102
|
- lib/loc_mods/name_part.rb
|
|
102
103
|
- lib/loc_mods/namespace.rb
|