loc_mods 0.2.3 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +2 -0
- data/.rubocop_todo.yml +83 -0
- data/README.adoc +48 -6
- data/lib/loc_mods/abstract.rb +9 -9
- data/lib/loc_mods/access_condition.rb +11 -11
- data/lib/loc_mods/alternative_name.rb +10 -10
- data/lib/loc_mods/area.rb +3 -3
- data/lib/loc_mods/cartographic_extension.rb +4 -4
- data/lib/loc_mods/cartographics.rb +8 -8
- data/lib/loc_mods/city_section.rb +3 -3
- data/lib/loc_mods/classification.rb +8 -8
- data/lib/loc_mods/cli.rb +48 -80
- data/lib/loc_mods/collection.rb +3 -3
- data/lib/loc_mods/copy_information.rb +5 -5
- data/lib/loc_mods/date.rb +8 -8
- data/lib/loc_mods/date_other.rb +4 -4
- data/lib/loc_mods/detail.rb +7 -7
- data/lib/loc_mods/edition.rb +4 -4
- data/lib/loc_mods/enumeration_and_chronology.rb +4 -4
- data/lib/loc_mods/extent.rb +4 -4
- data/lib/loc_mods/extent_definition.rb +7 -7
- data/lib/loc_mods/form.rb +5 -5
- data/lib/loc_mods/genre.rb +8 -8
- data/lib/loc_mods/geographic_code.rb +6 -6
- data/lib/loc_mods/hierarchical_geographic.rb +6 -6
- data/lib/loc_mods/hierarchical_part.rb +8 -8
- data/lib/loc_mods/holding_simple.rb +2 -2
- data/lib/loc_mods/identifier.rb +8 -8
- data/lib/loc_mods/item_identifier.rb +4 -4
- data/lib/loc_mods/language.rb +9 -9
- data/lib/loc_mods/language_term.rb +7 -7
- data/lib/loc_mods/location.rb +8 -8
- data/lib/loc_mods/name.rb +19 -19
- data/lib/loc_mods/name_part.rb +4 -4
- data/lib/loc_mods/non_sort.rb +4 -4
- data/lib/loc_mods/note.rb +7 -7
- data/lib/loc_mods/occupation.rb +6 -6
- data/lib/loc_mods/origin_info.rb +10 -10
- data/lib/loc_mods/part.rb +10 -10
- data/lib/loc_mods/physical_description.rb +10 -10
- data/lib/loc_mods/physical_description_note.rb +7 -7
- data/lib/loc_mods/physical_location.rb +5 -5
- data/lib/loc_mods/place.rb +3 -3
- data/lib/loc_mods/place_term.rb +7 -7
- data/lib/loc_mods/publisher.rb +6 -6
- data/lib/loc_mods/record.rb +4 -4
- data/lib/loc_mods/record_content_source.rb +4 -4
- data/lib/loc_mods/record_identifier.rb +4 -4
- data/lib/loc_mods/record_info.rb +9 -9
- data/lib/loc_mods/record_info_note.rb +8 -8
- data/lib/loc_mods/region.rb +3 -3
- data/lib/loc_mods/related_item.rb +10 -10
- data/lib/loc_mods/role.rb +2 -2
- data/lib/loc_mods/role_term.rb +4 -4
- data/lib/loc_mods/script_term.rb +4 -4
- data/lib/loc_mods/string_plus_language.rb +6 -6
- data/lib/loc_mods/string_plus_language_plus_authority.rb +6 -6
- data/lib/loc_mods/string_plus_language_plus_supplied.rb +4 -4
- data/lib/loc_mods/subject.rb +15 -15
- data/lib/loc_mods/subject_name.rb +14 -14
- data/lib/loc_mods/subject_title_info.rb +16 -16
- data/lib/loc_mods/table_of_contents.rb +9 -9
- data/lib/loc_mods/target_audience.rb +5 -5
- data/lib/loc_mods/temporal.rb +5 -5
- data/lib/loc_mods/text.rb +5 -5
- data/lib/loc_mods/title_info.rb +22 -22
- data/lib/loc_mods/type_of_resource.rb +8 -8
- data/lib/loc_mods/url.rb +8 -8
- data/lib/loc_mods/version.rb +1 -1
- data/lib/loc_mods.rb +7 -6
- data/references/allrecords-MODS.xml +1 -1
- metadata +5 -6
- data/lib/loc_mods/base_mapper.rb +0 -26
- data/lib/loc_mods/comparable_mapper.rb +0 -110
data/lib/loc_mods.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require "lutaml/model"
|
4
|
+
|
5
|
+
Lutaml::Model::Config.configure do |config|
|
6
|
+
require "lutaml/model/xml_adapter/nokogiri_adapter"
|
7
|
+
config.xml_adapter = Lutaml::Model::XmlAdapter::NokogiriAdapter
|
8
|
+
end
|
4
9
|
|
5
10
|
module LocMods
|
6
11
|
class Error < StandardError; end
|
7
|
-
# Your code goes here...
|
8
12
|
end
|
9
13
|
|
10
|
-
|
11
|
-
require "shale/adapter/nokogiri"
|
12
|
-
Shale.xml_adapter = Shale::Adapter::Nokogiri
|
13
|
-
|
14
|
+
require_relative "loc_mods/version"
|
14
15
|
require_relative "loc_mods/collection"
|
@@ -1863916,4 +1863916,4 @@
|
|
1863916
1863916
|
</languageOfCataloging>
|
1863917
1863917
|
</recordInfo>
|
1863918
1863918
|
</mods>
|
1863919
|
-
</modsCollection>
|
1863919
|
+
</modsCollection>
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loc_mods
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: lutaml-model
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -132,6 +132,7 @@ extra_rdoc_files: []
|
|
132
132
|
files:
|
133
133
|
- ".rspec"
|
134
134
|
- ".rubocop.yml"
|
135
|
+
- ".rubocop_todo.yml"
|
135
136
|
- CODE_OF_CONDUCT.md
|
136
137
|
- README.adoc
|
137
138
|
- Rakefile
|
@@ -141,14 +142,12 @@ files:
|
|
141
142
|
- lib/loc_mods/access_condition.rb
|
142
143
|
- lib/loc_mods/alternative_name.rb
|
143
144
|
- lib/loc_mods/area.rb
|
144
|
-
- lib/loc_mods/base_mapper.rb
|
145
145
|
- lib/loc_mods/cartographic_extension.rb
|
146
146
|
- lib/loc_mods/cartographics.rb
|
147
147
|
- lib/loc_mods/city_section.rb
|
148
148
|
- lib/loc_mods/classification.rb
|
149
149
|
- lib/loc_mods/cli.rb
|
150
150
|
- lib/loc_mods/collection.rb
|
151
|
-
- lib/loc_mods/comparable_mapper.rb
|
152
151
|
- lib/loc_mods/copy_information.rb
|
153
152
|
- lib/loc_mods/date.rb
|
154
153
|
- lib/loc_mods/date_other.rb
|
data/lib/loc_mods/base_mapper.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# lib/loc_mods/base_mapper.rb
|
4
|
-
require "shale"
|
5
|
-
require_relative "comparable_mapper"
|
6
|
-
|
7
|
-
module LocMods
|
8
|
-
# Base class for all object definitions
|
9
|
-
class BaseMapper < Shale::Mapper
|
10
|
-
include ComparableMapper
|
11
|
-
end
|
12
|
-
|
13
|
-
# Nil class substitute for comparison
|
14
|
-
class ComparableNil < BaseMapper
|
15
|
-
end
|
16
|
-
|
17
|
-
# Comparison of two values for ComparableMapper
|
18
|
-
class Comparison
|
19
|
-
attr_accessor :original, :updated
|
20
|
-
|
21
|
-
def initialize(original:, updated:)
|
22
|
-
@original = original
|
23
|
-
@updated = updated
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,110 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
# lib/loc_mods/comparable_mapper.rb
|
4
|
-
|
5
|
-
module LocMods
|
6
|
-
# Enable comparison of two class models solely based on attribute values in
|
7
|
-
# a recursive manner.
|
8
|
-
module ComparableMapper
|
9
|
-
# TODO: Implement Comparable
|
10
|
-
# include Comparable
|
11
|
-
# def <=>(other)
|
12
|
-
# attributes.foo <=> other.attributes.foo
|
13
|
-
# end
|
14
|
-
# def inspect
|
15
|
-
# @foo
|
16
|
-
# end
|
17
|
-
|
18
|
-
def eql?(other)
|
19
|
-
other.class == self.class &&
|
20
|
-
self.class.attributes.all? do |attr|
|
21
|
-
send(attr) == other.send(attr)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
alias == eql?
|
26
|
-
|
27
|
-
def hash
|
28
|
-
([self.class] + self.class.attributes.map(&:hash)).hash
|
29
|
-
end
|
30
|
-
|
31
|
-
def compare(other)
|
32
|
-
differences = {}
|
33
|
-
|
34
|
-
# puts "Debugging: Attributes for #{self.class.name}"
|
35
|
-
# pp self.class.attributes.keys
|
36
|
-
|
37
|
-
self.class.attributes.each_key do |attr|
|
38
|
-
self_value = respond_to?(attr) ? send(attr) : nil
|
39
|
-
other_value = other.respond_to?(attr) ? other.send(attr) : nil
|
40
|
-
|
41
|
-
# puts "Debugging: Comparing attribute '#{attr}'"
|
42
|
-
# puts " Self value: #{self_value.inspect}"
|
43
|
-
# puts " Other value: #{other_value.inspect}"
|
44
|
-
|
45
|
-
compared = compare_values(self_value, other_value)
|
46
|
-
if compared
|
47
|
-
# puts "DETECTED DIFFERENCE! #{compared.inspect}"
|
48
|
-
differences[attr] = compared
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
# unless differences.empty?
|
53
|
-
# puts "DIFFERENCES ARE"
|
54
|
-
# pp differences
|
55
|
-
# end
|
56
|
-
|
57
|
-
differences.empty? ? nil : differences
|
58
|
-
end
|
59
|
-
|
60
|
-
private
|
61
|
-
|
62
|
-
def compare_values(self_value, other_value)
|
63
|
-
# puts "compare_values (self_value: #{self_value}, other_value: #{other_value})"
|
64
|
-
case self_value
|
65
|
-
when Array
|
66
|
-
# puts "compare_values case 1"
|
67
|
-
compare_arrays(self_value, other_value || [])
|
68
|
-
when ComparableMapper
|
69
|
-
# puts "compare_values case 2"
|
70
|
-
self_value.compare(other_value)
|
71
|
-
else
|
72
|
-
if self_value != other_value
|
73
|
-
# puts "compare_values case 3"
|
74
|
-
Comparison.new(original: self_value, updated: other_value)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
def compare_arrays(self_array, other_array)
|
80
|
-
differences = {}
|
81
|
-
max_length = [self_array.size, other_array.size].max
|
82
|
-
|
83
|
-
max_length.times do |index|
|
84
|
-
self_item = self_array[index] || ComparableNil.new
|
85
|
-
other_item = other_array[index] || ComparableNil.new
|
86
|
-
|
87
|
-
compared = compare_values(self_item, other_item)
|
88
|
-
differences[index] = compared if compared
|
89
|
-
|
90
|
-
# if index >= self_array.size
|
91
|
-
# puts "case 1 #{compared}"
|
92
|
-
# # differences[index] = compared
|
93
|
-
# elsif index >= other_array.size
|
94
|
-
# puts "case 2.1 #{self_item}"
|
95
|
-
# puts "case 2.2 #{compared}"
|
96
|
-
# # differences[index] = compared
|
97
|
-
# end
|
98
|
-
end
|
99
|
-
|
100
|
-
if self_array.size != other_array.size
|
101
|
-
differences[:_array_size_difference] = Comparison.new(
|
102
|
-
original: self_array.size,
|
103
|
-
updated: other_array.size
|
104
|
-
)
|
105
|
-
end
|
106
|
-
|
107
|
-
differences.empty? ? nil : differences
|
108
|
-
end
|
109
|
-
end
|
110
|
-
end
|