loc_mods 0.2.7 → 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/.rubocop.yml +16 -7
- data/.rubocop_todo.yml +38 -37
- data/README.adoc +44 -0
- data/lib/loc_mods/abstract.rb +2 -2
- data/lib/loc_mods/access_condition.rb +2 -2
- data/lib/loc_mods/alternative_name.rb +2 -2
- data/lib/loc_mods/area.rb +2 -2
- data/lib/loc_mods/cartographic_extension.rb +2 -2
- data/lib/loc_mods/cartographics.rb +2 -2
- data/lib/loc_mods/city_section.rb +2 -2
- data/lib/loc_mods/classification.rb +2 -2
- data/lib/loc_mods/cli.rb +15 -9
- data/lib/loc_mods/collection.rb +2 -2
- data/lib/loc_mods/copy_information.rb +2 -2
- data/lib/loc_mods/date.rb +4 -4
- data/lib/loc_mods/date_other.rb +2 -2
- data/lib/loc_mods/detail.rb +2 -2
- data/lib/loc_mods/edition.rb +2 -2
- data/lib/loc_mods/enumeration_and_chronology.rb +2 -2
- data/lib/loc_mods/extent.rb +2 -2
- data/lib/loc_mods/extent_definition.rb +2 -2
- data/lib/loc_mods/form.rb +2 -2
- data/lib/loc_mods/genre.rb +2 -2
- data/lib/loc_mods/geographic_code.rb +4 -2
- data/lib/loc_mods/hierarchical_geographic.rb +2 -2
- data/lib/loc_mods/hierarchical_part.rb +2 -2
- data/lib/loc_mods/holding_simple.rb +2 -2
- data/lib/loc_mods/identifier.rb +2 -2
- data/lib/loc_mods/item_identifier.rb +2 -2
- data/lib/loc_mods/language.rb +2 -2
- data/lib/loc_mods/language_term.rb +4 -2
- data/lib/loc_mods/location.rb +2 -2
- data/lib/loc_mods/marc_code_lookup.rb +54 -0
- data/lib/loc_mods/name.rb +4 -6
- data/lib/loc_mods/name_part.rb +2 -2
- data/lib/loc_mods/namespace.rb +10 -0
- data/lib/loc_mods/non_sort.rb +4 -5
- data/lib/loc_mods/note.rb +2 -2
- data/lib/loc_mods/occupation.rb +2 -2
- data/lib/loc_mods/origin_info.rb +3 -2
- data/lib/loc_mods/part.rb +2 -2
- data/lib/loc_mods/physical_description.rb +3 -2
- data/lib/loc_mods/physical_description_note.rb +2 -2
- data/lib/loc_mods/physical_location.rb +2 -2
- data/lib/loc_mods/place.rb +2 -2
- data/lib/loc_mods/place_term.rb +4 -2
- data/lib/loc_mods/publisher.rb +2 -2
- data/lib/loc_mods/record.rb +3 -2
- data/lib/loc_mods/record_content_source.rb +1 -1
- data/lib/loc_mods/record_identifier.rb +2 -2
- data/lib/loc_mods/record_info.rb +2 -2
- data/lib/loc_mods/record_info_note.rb +2 -2
- data/lib/loc_mods/region.rb +2 -2
- data/lib/loc_mods/related_item.rb +4 -6
- data/lib/loc_mods/role.rb +2 -2
- data/lib/loc_mods/role_term.rb +10 -2
- data/lib/loc_mods/script_term.rb +2 -2
- data/lib/loc_mods/string_plus_language.rb +2 -2
- data/lib/loc_mods/subject.rb +6 -7
- data/lib/loc_mods/subject_name.rb +2 -2
- data/lib/loc_mods/subject_title_info.rb +2 -2
- data/lib/loc_mods/table_of_contents.rb +2 -2
- data/lib/loc_mods/target_audience.rb +2 -2
- data/lib/loc_mods/temporal.rb +2 -2
- data/lib/loc_mods/text.rb +2 -2
- data/lib/loc_mods/title_info.rb +2 -2
- data/lib/loc_mods/type_of_resource.rb +2 -2
- data/lib/loc_mods/url.rb +2 -2
- data/lib/loc_mods/version.rb +1 -1
- data/lib/loc_mods/xlink_href.rb +9 -0
- data/lib/loc_mods/xlink_namespace.rb +8 -0
- data/lib/loc_mods/xml_space.rb +9 -0
- data/lib/loc_mods.rb +72 -8
- metadata +17 -11
data/lib/loc_mods/location.rb
CHANGED
|
@@ -21,8 +21,8 @@ module LocMods
|
|
|
21
21
|
attribute :holding_external, CartographicExtension
|
|
22
22
|
|
|
23
23
|
xml do
|
|
24
|
-
|
|
25
|
-
namespace
|
|
24
|
+
element "location"
|
|
25
|
+
namespace Namespace
|
|
26
26
|
|
|
27
27
|
map_attribute "lang", to: :lang
|
|
28
28
|
map_attribute "script", to: :script
|
|
@@ -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/name.rb
CHANGED
|
@@ -29,15 +29,13 @@ module LocMods
|
|
|
29
29
|
attribute :name_identifier, Identifier, collection: true
|
|
30
30
|
attribute :alternative_name, AlternativeName, collection: true
|
|
31
31
|
attribute :etal, :string
|
|
32
|
-
attribute :href,
|
|
32
|
+
attribute :href, XlinkHref
|
|
33
33
|
|
|
34
34
|
xml do
|
|
35
|
-
|
|
36
|
-
namespace
|
|
35
|
+
element "name"
|
|
36
|
+
namespace Namespace
|
|
37
37
|
|
|
38
|
-
map_attribute "href", to: :href
|
|
39
|
-
namespace: "http://www.w3.org/1999/xlink",
|
|
40
|
-
prefix: "xlink"
|
|
38
|
+
map_attribute "href", to: :href
|
|
41
39
|
|
|
42
40
|
map_attribute "ID", to: :id
|
|
43
41
|
map_attribute "authority", to: :authority
|
data/lib/loc_mods/name_part.rb
CHANGED
data/lib/loc_mods/non_sort.rb
CHANGED
|
@@ -5,15 +5,14 @@ require "lutaml/model"
|
|
|
5
5
|
module LocMods
|
|
6
6
|
class NonSort < Lutaml::Model::Serializable
|
|
7
7
|
attribute :content, :string
|
|
8
|
-
attribute :space,
|
|
8
|
+
attribute :space, ::Lutaml::Xml::W3c::XmlSpaceType
|
|
9
9
|
|
|
10
10
|
xml do
|
|
11
|
-
|
|
12
|
-
namespace
|
|
11
|
+
element "nonSort"
|
|
12
|
+
namespace Namespace
|
|
13
13
|
|
|
14
14
|
map_content to: :content
|
|
15
|
-
map_attribute "space", to: :space
|
|
16
|
-
namespace: "http://www.w3.org/XML/1998/namespace", prefix: "xml"
|
|
15
|
+
map_attribute "space", to: :space
|
|
17
16
|
end
|
|
18
17
|
end
|
|
19
18
|
end
|
data/lib/loc_mods/note.rb
CHANGED
data/lib/loc_mods/occupation.rb
CHANGED
data/lib/loc_mods/origin_info.rb
CHANGED
|
@@ -30,8 +30,9 @@ module LocMods
|
|
|
30
30
|
attribute :frequency, :string, collection: true
|
|
31
31
|
|
|
32
32
|
xml do
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
element "originInfo"
|
|
34
|
+
ordered
|
|
35
|
+
namespace Namespace
|
|
35
36
|
|
|
36
37
|
map_attribute "lang", to: :lang
|
|
37
38
|
map_attribute "script", to: :script
|
data/lib/loc_mods/part.rb
CHANGED
|
@@ -21,8 +21,9 @@ module LocMods
|
|
|
21
21
|
attribute :note, PhysicalDescriptionNote, collection: true
|
|
22
22
|
|
|
23
23
|
xml do
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
element "physicalDescription"
|
|
25
|
+
ordered
|
|
26
|
+
namespace Namespace
|
|
26
27
|
|
|
27
28
|
map_attribute "lang", to: :lang
|
|
28
29
|
map_attribute "script", to: :script
|
|
@@ -11,8 +11,8 @@ module LocMods
|
|
|
11
11
|
attribute :id, :string
|
|
12
12
|
|
|
13
13
|
xml do
|
|
14
|
-
|
|
15
|
-
namespace
|
|
14
|
+
element "physicalDescriptionNote"
|
|
15
|
+
namespace Namespace
|
|
16
16
|
|
|
17
17
|
map_content to: :content
|
|
18
18
|
map_attribute "displayLabel", to: :display_label
|
|
@@ -9,8 +9,8 @@ module LocMods
|
|
|
9
9
|
attribute :type, :string
|
|
10
10
|
|
|
11
11
|
xml do
|
|
12
|
-
|
|
13
|
-
namespace
|
|
12
|
+
element "physicalLocation"
|
|
13
|
+
namespace Namespace
|
|
14
14
|
|
|
15
15
|
map_content to: :content
|
|
16
16
|
map_attribute "displayLabel", to: :display_label
|
data/lib/loc_mods/place.rb
CHANGED
|
@@ -10,8 +10,8 @@ module LocMods
|
|
|
10
10
|
attribute :place_term, PlaceTerm, collection: true
|
|
11
11
|
|
|
12
12
|
xml do
|
|
13
|
-
|
|
14
|
-
namespace
|
|
13
|
+
element "place"
|
|
14
|
+
namespace Namespace
|
|
15
15
|
|
|
16
16
|
map_attribute "supplied", to: :supplied
|
|
17
17
|
map_element "placeTerm", to: :place_term
|
data/lib/loc_mods/place_term.rb
CHANGED
|
@@ -4,6 +4,8 @@ require "lutaml/model"
|
|
|
4
4
|
|
|
5
5
|
module LocMods
|
|
6
6
|
class PlaceTerm < Lutaml::Model::Serializable
|
|
7
|
+
include MarcCodeLookup
|
|
8
|
+
|
|
7
9
|
attribute :content, :string
|
|
8
10
|
attribute :authority_uri, :string
|
|
9
11
|
attribute :value_uri, :string
|
|
@@ -11,8 +13,8 @@ module LocMods
|
|
|
11
13
|
attribute :type, :string
|
|
12
14
|
|
|
13
15
|
xml do
|
|
14
|
-
|
|
15
|
-
namespace
|
|
16
|
+
element "placeTerm"
|
|
17
|
+
namespace Namespace
|
|
16
18
|
|
|
17
19
|
map_content to: :content
|
|
18
20
|
map_attribute "authorityURI", to: :authority_uri
|
data/lib/loc_mods/publisher.rb
CHANGED
data/lib/loc_mods/record.rb
CHANGED
|
@@ -49,8 +49,9 @@ module LocMods
|
|
|
49
49
|
attribute :type_of_resource, TypeOfResource, collection: true
|
|
50
50
|
|
|
51
51
|
xml do
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
element "mods"
|
|
53
|
+
ordered
|
|
54
|
+
namespace Namespace
|
|
54
55
|
|
|
55
56
|
map_attribute "ID", to: :id
|
|
56
57
|
map_attribute "version", to: :version
|
data/lib/loc_mods/record_info.rb
CHANGED
|
@@ -25,8 +25,8 @@ module LocMods
|
|
|
25
25
|
attribute :record_info_note, RecordInfoNote, collection: true
|
|
26
26
|
|
|
27
27
|
xml do
|
|
28
|
-
|
|
29
|
-
namespace
|
|
28
|
+
element "recordInfo"
|
|
29
|
+
namespace Namespace
|
|
30
30
|
|
|
31
31
|
map_attribute "lang", to: :lang
|
|
32
32
|
map_attribute "script", to: :script
|
|
@@ -12,8 +12,8 @@ module LocMods
|
|
|
12
12
|
attribute :alt_rep_group, :string
|
|
13
13
|
|
|
14
14
|
xml do
|
|
15
|
-
|
|
16
|
-
namespace
|
|
15
|
+
element "recordInfoNote"
|
|
16
|
+
namespace Namespace
|
|
17
17
|
|
|
18
18
|
map_content to: :content
|
|
19
19
|
map_attribute "displayLabel", to: :display_label
|
data/lib/loc_mods/region.rb
CHANGED
|
@@ -51,11 +51,11 @@ module LocMods
|
|
|
51
51
|
attribute :target_audience, TargetAudience, collection: true
|
|
52
52
|
attribute :title_info, TitleInfo, collection: true
|
|
53
53
|
attribute :type_of_resource, TypeOfResource, collection: true
|
|
54
|
-
attribute :href,
|
|
54
|
+
attribute :href, XlinkHref
|
|
55
55
|
|
|
56
56
|
xml do
|
|
57
|
-
|
|
58
|
-
namespace
|
|
57
|
+
element "relatedItem"
|
|
58
|
+
namespace Namespace
|
|
59
59
|
|
|
60
60
|
map_attribute "type", to: :type
|
|
61
61
|
map_attribute "otherType", to: :other_type
|
|
@@ -64,9 +64,7 @@ module LocMods
|
|
|
64
64
|
map_attribute "otherTypeURI", to: :other_type_uri
|
|
65
65
|
map_attribute "displayLabel", to: :display_label
|
|
66
66
|
map_attribute "ID", to: :id
|
|
67
|
-
map_attribute "href", to: :href
|
|
68
|
-
namespace: "http://www.w3.org/1999/xlink",
|
|
69
|
-
prefix: "xlink"
|
|
67
|
+
map_attribute "href", to: :href
|
|
70
68
|
|
|
71
69
|
map_element "abstract", to: :abstract
|
|
72
70
|
map_element "accessCondition", to: :access_condition
|
data/lib/loc_mods/role.rb
CHANGED
data/lib/loc_mods/role_term.rb
CHANGED
|
@@ -4,14 +4,22 @@ 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
|
|
11
|
-
|
|
12
|
-
namespace
|
|
16
|
+
element "roleTerm"
|
|
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/script_term.rb
CHANGED
data/lib/loc_mods/subject.rb
CHANGED
|
@@ -33,15 +33,14 @@ module LocMods
|
|
|
33
33
|
attribute :cartographics, Cartographics, collection: true
|
|
34
34
|
attribute :occupation, Occupation, collection: true
|
|
35
35
|
attribute :genre, Genre, collection: true
|
|
36
|
-
attribute :href,
|
|
36
|
+
attribute :href, XlinkHref
|
|
37
37
|
|
|
38
38
|
xml do
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
element "subject"
|
|
40
|
+
ordered
|
|
41
|
+
namespace Namespace
|
|
41
42
|
|
|
42
|
-
map_attribute "href", to: :href
|
|
43
|
-
namespace: "http://www.w3.org/1999/xlink",
|
|
44
|
-
prefix: "xlink"
|
|
43
|
+
map_attribute "href", to: :href
|
|
45
44
|
|
|
46
45
|
map_attribute "ID", to: :id
|
|
47
46
|
map_attribute "authority", to: :authority
|
|
@@ -56,7 +55,7 @@ module LocMods
|
|
|
56
55
|
|
|
57
56
|
map_element "name", to: :name
|
|
58
57
|
map_element "titleInfo", to: :title_info
|
|
59
|
-
map_element "topic", to: :topic
|
|
58
|
+
map_element "topic", to: :topic, render_empty: :as_blank
|
|
60
59
|
map_element "geographic", to: :geographic
|
|
61
60
|
map_element "temporal", to: :temporal
|
|
62
61
|
map_element "geographicCode", to: :geographic_code
|
|
@@ -25,8 +25,8 @@ module LocMods
|
|
|
25
25
|
attribute :name_identifier, Identifier, collection: true
|
|
26
26
|
|
|
27
27
|
xml do
|
|
28
|
-
|
|
29
|
-
namespace
|
|
28
|
+
element "subjectName"
|
|
29
|
+
namespace Namespace
|
|
30
30
|
|
|
31
31
|
map_attribute "type", to: :type
|
|
32
32
|
map_attribute "ID", to: :id
|
|
@@ -20,8 +20,8 @@ module LocMods
|
|
|
20
20
|
attribute :non_sort, :string, collection: true
|
|
21
21
|
|
|
22
22
|
xml do
|
|
23
|
-
|
|
24
|
-
namespace
|
|
23
|
+
element "subjectTitleInfo"
|
|
24
|
+
namespace Namespace
|
|
25
25
|
|
|
26
26
|
map_attribute "ID", to: :id
|
|
27
27
|
map_attribute "authority", to: :authority
|
|
@@ -13,8 +13,8 @@ module LocMods
|
|
|
13
13
|
attribute :content_type, :string
|
|
14
14
|
|
|
15
15
|
xml do
|
|
16
|
-
|
|
17
|
-
namespace
|
|
16
|
+
element "tableOfContents"
|
|
17
|
+
namespace Namespace
|
|
18
18
|
|
|
19
19
|
map_content to: :content
|
|
20
20
|
map_attribute "displayLabel", to: :display_label
|
|
@@ -10,8 +10,8 @@ module LocMods
|
|
|
10
10
|
attribute :alt_rep_group, :string
|
|
11
11
|
|
|
12
12
|
xml do
|
|
13
|
-
|
|
14
|
-
namespace
|
|
13
|
+
element "targetAudience"
|
|
14
|
+
namespace Namespace
|
|
15
15
|
|
|
16
16
|
map_content to: :content
|
|
17
17
|
map_attribute "authority", to: :authority
|
data/lib/loc_mods/temporal.rb
CHANGED
data/lib/loc_mods/text.rb
CHANGED
data/lib/loc_mods/title_info.rb
CHANGED
|
@@ -28,8 +28,8 @@ module LocMods
|
|
|
28
28
|
attribute :non_sort, NonSort, collection: true
|
|
29
29
|
|
|
30
30
|
xml do
|
|
31
|
-
|
|
32
|
-
namespace
|
|
31
|
+
element "titleInfo"
|
|
32
|
+
namespace Namespace
|
|
33
33
|
|
|
34
34
|
map_attribute "type", to: :type
|
|
35
35
|
map_attribute "otherType", to: :other_type
|
|
@@ -12,8 +12,8 @@ module LocMods
|
|
|
12
12
|
attribute :usage, :string
|
|
13
13
|
|
|
14
14
|
xml do
|
|
15
|
-
|
|
16
|
-
namespace
|
|
15
|
+
element "typeOfResource"
|
|
16
|
+
namespace Namespace
|
|
17
17
|
|
|
18
18
|
map_content to: :content
|
|
19
19
|
map_attribute "collection", to: :collection
|
data/lib/loc_mods/url.rb
CHANGED
data/lib/loc_mods/version.rb
CHANGED