relaton-bib 1.0.1 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/grammars/basicdoc.rng +986 -0
- data/grammars/biblio.rng +1237 -0
- data/grammars/isodoc.rng +1504 -0
- data/grammars/reqt.rng +171 -0
- data/lib/relaton_bib.rb +7 -4
- data/lib/relaton_bib/bibliographic_item.rb +128 -26
- data/lib/relaton_bib/bibtex_parser.rb +22 -20
- data/lib/relaton_bib/copyright_association.rb +28 -9
- data/lib/relaton_bib/document_relation.rb +22 -10
- data/lib/relaton_bib/document_relation_collection.rb +5 -5
- data/lib/relaton_bib/document_status.rb +49 -10
- data/lib/relaton_bib/editorial_group.rb +27 -0
- data/lib/relaton_bib/formatted_string.rb +3 -3
- data/lib/relaton_bib/hash_converter.rb +96 -26
- data/lib/relaton_bib/ics.rb +26 -0
- data/lib/relaton_bib/localized_string.rb +33 -12
- data/lib/relaton_bib/structured_identifier.rb +141 -0
- data/lib/relaton_bib/technical_committee.rb +25 -0
- data/lib/relaton_bib/typed_title_string.rb +39 -9
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/workgroup.rb +36 -0
- data/lib/relaton_bib/xml_parser.rb +85 -27
- data/relaton-bib.gemspec +3 -3
- metadata +25 -16
@@ -147,17 +147,16 @@ module RelatonBib
|
|
147
147
|
# @param bibtex [BibTeX::Entry]
|
148
148
|
# @return [Array<RelatonBib::BiblioNote>]
|
149
149
|
def fetch_note(bibtex)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
150
|
+
bibtex.select do |k, _v|
|
151
|
+
%i[annote howpublished comment note content].include? k
|
152
|
+
end.reduce([]) do |mem, note|
|
153
|
+
type = case note[0]
|
154
|
+
when :note then nil
|
155
|
+
when :content then "tableOfContents"
|
156
|
+
else note[0].to_s
|
157
|
+
end
|
158
|
+
mem << BiblioNote.new(type: type, content: note[1].to_s)
|
155
159
|
end
|
156
|
-
|
157
|
-
note << BiblioNote.new(type: "comment", content: bibtex.comment.to_s) if bibtex["comment"]
|
158
|
-
note << BiblioNote.new(content: bibtex.note.to_s) if bibtex["note"]
|
159
|
-
note << BiblioNote.new(type: "tableOfContents", content: bibtex["content"]) if bibtex["content"]
|
160
|
-
note
|
161
160
|
end
|
162
161
|
|
163
162
|
# @param bibtex [BibTeX::Entry]
|
@@ -172,16 +171,19 @@ module RelatonBib
|
|
172
171
|
# @param bibtex [BibTeX::Entry]
|
173
172
|
# @return [Array<RelatonBib::BibItemLocality>]
|
174
173
|
def fetch_extent(bibtex)
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
174
|
+
bibtex.select do |k, _v|
|
175
|
+
%i[chapter pages volume].include? k
|
176
|
+
end.reduce([]) do |mem, loc|
|
177
|
+
if loc[0] == :pages
|
178
|
+
type = "page"
|
179
|
+
from, to = loc[1].to_s.split "-"
|
180
|
+
else
|
181
|
+
type = loc[0].to_s
|
182
|
+
from = loc[1].to_s
|
183
|
+
to = nil
|
184
|
+
end
|
185
|
+
mem << BibItemLocality.new(type, from, to)
|
181
186
|
end
|
182
|
-
|
183
|
-
extent << BibItemLocality.new("volume", bibtex.volume.to_s) if bibtex["volume"]
|
184
|
-
extent
|
185
187
|
end
|
186
188
|
|
187
189
|
# @param bibtex [BibTeX::Entry]
|
@@ -192,7 +194,7 @@ module RelatonBib
|
|
192
194
|
series << Series.new(
|
193
195
|
type: "journal",
|
194
196
|
title: TypedTitleString.new(content: bibtex.journal.to_s),
|
195
|
-
number: bibtex["number"]&.to_s
|
197
|
+
number: bibtex["number"]&.to_s,
|
196
198
|
)
|
197
199
|
end
|
198
200
|
|
@@ -1,29 +1,41 @@
|
|
1
1
|
module RelatonBib
|
2
2
|
# Copyright association.
|
3
3
|
class CopyrightAssociation
|
4
|
+
include RelatonBib
|
5
|
+
|
4
6
|
# @return [Date]
|
5
7
|
attr_reader :from
|
6
8
|
|
7
9
|
# @return [Date, NilClass]
|
8
10
|
attr_reader :to
|
9
11
|
|
10
|
-
# @return [
|
12
|
+
# @return [String, NilClass]
|
13
|
+
attr_reader :scope
|
14
|
+
|
15
|
+
# @return [Array<RelatonBib::ContributionInfo>]
|
11
16
|
attr_reader :owner
|
12
17
|
|
13
|
-
#
|
18
|
+
# rubocop:disable Metrics/AbcSize
|
19
|
+
|
20
|
+
# @param owner [Array<Hash, RelatonBib::ContributionInfo>] contributor
|
14
21
|
# @option owner [String] :name
|
15
22
|
# @option owner [String] :abbreviation
|
16
23
|
# @option owner [String] :url
|
17
24
|
# @param from [String] date
|
18
25
|
# @param to [String, NilClass] date
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
26
|
+
# @param scope [String, NilClass]
|
27
|
+
def initialize(owner:, from:, to: nil, scope: nil)
|
28
|
+
unless owner.any?
|
29
|
+
raise ArgumentError, "at least one owner should exist."
|
30
|
+
end
|
31
|
+
|
32
|
+
@owner = owner.map do |o|
|
33
|
+
o.is_a?(Hash) ? ContributionInfo.new(entity: Organization.new(o)) : o
|
34
|
+
end
|
24
35
|
|
25
36
|
@from = Date.strptime(from.to_s, "%Y") if from.to_s =~ /\d{4}/
|
26
37
|
@to = Date.strptime(to.to_s, "%Y") unless to.to_s.empty?
|
38
|
+
@scope = scope
|
27
39
|
end
|
28
40
|
|
29
41
|
# @param builder [Nokogiri::XML::Builder]
|
@@ -31,14 +43,21 @@ module RelatonBib
|
|
31
43
|
builder.copyright do
|
32
44
|
builder.from from ? from.year : "unknown"
|
33
45
|
builder.to to.year if to
|
34
|
-
builder.owner {
|
46
|
+
owner.each { |o| builder.owner { o.to_xml builder } }
|
47
|
+
builder.scope scope if scope
|
35
48
|
end
|
36
49
|
end
|
50
|
+
# rubocop:enable Metrics/AbcSize
|
37
51
|
|
38
52
|
# @return [Hash]
|
39
53
|
def to_hash
|
40
|
-
|
54
|
+
owners = single_element_array(owner.map { |o| o.to_hash["organization"] })
|
55
|
+
hash = {
|
56
|
+
"owner" => owners,
|
57
|
+
"from" => from.year.to_s,
|
58
|
+
}
|
41
59
|
hash["to"] = to.year.to_s if to
|
60
|
+
hash["scope"] = scope if scope
|
42
61
|
hash
|
43
62
|
end
|
44
63
|
end
|
@@ -4,11 +4,16 @@ module RelatonBib
|
|
4
4
|
include RelatonBib
|
5
5
|
|
6
6
|
TYPES = %w[
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
includes includedIn hasPart partOf merges mergedInto splits splitInto
|
8
|
+
instance hasInstance exemplarOf hasExemplar manifestationOf
|
9
|
+
hasManifestation reproductionOf hasReproduction reprintOf hasReprint
|
10
|
+
expressionOf hasExpression translatedFrom hasTranslation arrangementOf
|
11
|
+
hasArrangement abridgementOf hasAbridgement annotationOf hasAnnotation
|
12
|
+
draftOf hasDraft editionOf hasEdition updates updatedBy derivedFrom
|
13
|
+
derives describes describedBy catalogues cataloguedBy hasSuccessor
|
14
|
+
successorOf adaptedFrom hasAdaptation adoptedFrom adoptedAs reviewOf
|
15
|
+
hasReview commentaryOf hasCommentary related complements complementOf
|
16
|
+
obsoletes obsoletedBy cited isCitedIn
|
12
17
|
].freeze
|
13
18
|
|
14
19
|
# @return [String]
|
@@ -26,16 +31,20 @@ module RelatonBib
|
|
26
31
|
# @return [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
|
27
32
|
attr_reader :locality
|
28
33
|
|
29
|
-
# @return [Array<RelatonBib::SourceLocality,
|
34
|
+
# @return [Array<RelatonBib::SourceLocality,
|
35
|
+
# RelatonBib::SourceLocalityStack>]
|
30
36
|
attr_reader :source_locality
|
31
37
|
|
32
38
|
# @param type [String]
|
33
39
|
# @parma description [RelatonBib::FormattedString, NilClass]
|
34
|
-
# @param bibitem [RelatonBib::BibliographicItem,
|
40
|
+
# @param bibitem [RelatonBib::BibliographicItem,
|
41
|
+
# RelatonIso::IsoBibliographicItem]
|
35
42
|
# @param locality [Array<RelatonBib::Locality, RelatonBib::LocalityStack>]
|
36
|
-
# @param source_locality [Array<RelatonBib::SourceLocality,
|
37
|
-
|
38
|
-
|
43
|
+
# @param source_locality [Array<RelatonBib::SourceLocality,
|
44
|
+
# RelatonBib::SourceLocalityStack>]
|
45
|
+
def initialize(type:, description: nil, bibitem:, locality: [],
|
46
|
+
source_locality: [])
|
47
|
+
type = "obsoletes" if type == "Now withdrawn"
|
39
48
|
unless TYPES.include? type
|
40
49
|
warn "[relaton-bib] WARNING: invalid relation type: #{type}"
|
41
50
|
end
|
@@ -46,6 +55,8 @@ module RelatonBib
|
|
46
55
|
@bibitem = bibitem
|
47
56
|
end
|
48
57
|
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
59
|
+
|
49
60
|
# @param builder [Nokogiri::XML::Builder]
|
50
61
|
def to_xml(builder, **opts)
|
51
62
|
opts.delete :bibdata
|
@@ -57,6 +68,7 @@ module RelatonBib
|
|
57
68
|
source_locality.each { |l| l.to_xml builder }
|
58
69
|
end
|
59
70
|
end
|
71
|
+
# rubocop:enable Metrics/AbcSize
|
60
72
|
|
61
73
|
# @return [Hash]
|
62
74
|
def to_hash
|
@@ -8,7 +8,7 @@ module RelatonBib
|
|
8
8
|
extend Forwardable
|
9
9
|
|
10
10
|
def_delegators :@array, :<<, :[], :first, :last, :empty?, :any?, :size,
|
11
|
-
|
11
|
+
:each, :detect, :map, :length
|
12
12
|
|
13
13
|
# @param relation [Array<RelatonBib::DocumentRelation, Hash>]
|
14
14
|
# @option relation [String] :type
|
@@ -20,15 +20,15 @@ module RelatonBib
|
|
20
20
|
# RelatonBib::SourceLocalityStack>] :source_locality
|
21
21
|
# @option relation [RelatonBib::BibliographicItem, NillClass] :bibitem (nil)
|
22
22
|
def initialize(relation)
|
23
|
-
@array =
|
23
|
+
@array = relation.map { |r| r.is_a?(Hash) ? DocumentRelation.new(r) : r }
|
24
24
|
end
|
25
25
|
|
26
26
|
# @todo We don't have replace type anymore. Suppose we should update this
|
27
27
|
# method or delete it.
|
28
28
|
#
|
29
29
|
# @return [RelatonBib::DocRelationCollection]
|
30
|
-
|
31
|
-
|
32
|
-
|
30
|
+
def replaces
|
31
|
+
DocRelationCollection.new(@array.select { |r| r.type == "replace" })
|
32
|
+
end
|
33
33
|
end
|
34
34
|
end
|
@@ -5,21 +5,21 @@ require "relaton_bib/localized_string"
|
|
5
5
|
module RelatonBib
|
6
6
|
# Document status.
|
7
7
|
class DocumentStatus
|
8
|
-
# @return [
|
8
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
9
9
|
attr_reader :stage
|
10
10
|
|
11
|
-
# @return [
|
11
|
+
# @return [RelatonBib::DocumentStatus::Stage, NilClass]
|
12
12
|
attr_reader :substage
|
13
13
|
|
14
14
|
# @return [String, NilClass]
|
15
15
|
attr_reader :iteration
|
16
16
|
|
17
|
-
# @param stage [String]
|
18
|
-
# @param substage [String, NilClass]
|
17
|
+
# @param stage [String, Hash, RelatonBib::DocumentStatus::Stage]
|
18
|
+
# @param substage [String, Hash, NilClass, RelatonBib::DocumentStatus::Stage]
|
19
19
|
# @param iteration [String, NilClass]
|
20
20
|
def initialize(stage:, substage: nil, iteration: nil)
|
21
|
-
@stage = stage
|
22
|
-
@substage = substage
|
21
|
+
@stage = stage_new stage
|
22
|
+
@substage = stage_new substage
|
23
23
|
@iteration = iteration
|
24
24
|
end
|
25
25
|
|
@@ -27,18 +27,57 @@ module RelatonBib
|
|
27
27
|
def to_xml(builder)
|
28
28
|
builder.status do
|
29
29
|
# FormattedString.instance_method(:to_xml).bind(status).call builder
|
30
|
-
builder.stage stage
|
31
|
-
builder.substage substage if substage
|
30
|
+
builder.stage { |b| stage.to_xml b }
|
31
|
+
builder.substage { |b| substage.to_xml b } if substage
|
32
32
|
builder.iteration iteration unless iteration.to_s.empty?
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
36
|
# @return [Hash]
|
37
37
|
def to_hash
|
38
|
-
hash = { "stage" => stage }
|
39
|
-
hash["substage"] = substage if substage
|
38
|
+
hash = { "stage" => stage.to_hash }
|
39
|
+
hash["substage"] = substage.to_hash if substage
|
40
40
|
hash["iteration"] = iteration if iteration
|
41
41
|
hash
|
42
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
# @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, NilClass]
|
47
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
48
|
+
def stage_new(stg)
|
49
|
+
if stg.is_a?(Stage) then stg
|
50
|
+
elsif stg.is_a?(Hash) then Stage.new(stg)
|
51
|
+
elsif stg.is_a?(String) then Stage.new(value: stg)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Stage
|
56
|
+
# @return [String]
|
57
|
+
attr_reader :value
|
58
|
+
|
59
|
+
# @return [String, NilClass]
|
60
|
+
attr_reader :abbreviation
|
61
|
+
|
62
|
+
# @parma value [String]
|
63
|
+
# @param abbreviation [String, NilClass]
|
64
|
+
def initialize(value:, abbreviation: nil)
|
65
|
+
@value = value
|
66
|
+
@abbreviation = abbreviation
|
67
|
+
end
|
68
|
+
|
69
|
+
# @param [Nokogiri::XML::Builder]
|
70
|
+
def to_xml(builder)
|
71
|
+
builder.parent[:abbreviation] = abbreviation if abbreviation
|
72
|
+
builder.text value
|
73
|
+
end
|
74
|
+
|
75
|
+
# @return [Hash]
|
76
|
+
def to_hash
|
77
|
+
hash = { "value" => value }
|
78
|
+
hash["abbreviation"] = abbreviation if abbreviation
|
79
|
+
hash
|
80
|
+
end
|
81
|
+
end
|
43
82
|
end
|
44
83
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "relaton_bib/technical_committee"
|
2
|
+
|
3
|
+
module RelatonBib
|
4
|
+
class EditorialGroup
|
5
|
+
include RelatonBib
|
6
|
+
|
7
|
+
# @return [Array<RelatonBib::TechnicalCommittee>]
|
8
|
+
attr_accessor :technical_committee
|
9
|
+
|
10
|
+
# @param technical_committee [Array<RelatonBib::TecnicalCommittee>]
|
11
|
+
def initialize(technical_committee)
|
12
|
+
@technical_committee = technical_committee
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param builder [Nokogigi::XML::Builder]
|
16
|
+
def to_xml(builder)
|
17
|
+
builder.editorialgroup do |b|
|
18
|
+
technical_committee.each { |tc| tc.to_xml b }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# @return [Hash]
|
23
|
+
def to_hash
|
24
|
+
single_element_array technical_committee
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -12,7 +12,7 @@ module RelatonBib
|
|
12
12
|
# @return [String]
|
13
13
|
attr_reader :format
|
14
14
|
|
15
|
-
# @param content [String]
|
15
|
+
# @param content [String, Array<RelatonBib::LocalizedString>]
|
16
16
|
# @param language [String, NilClass] language code Iso639
|
17
17
|
# @param script [String, NilClass] script code Iso15924
|
18
18
|
# @param format [String] the content type
|
@@ -36,8 +36,8 @@ module RelatonBib
|
|
36
36
|
hash = super
|
37
37
|
return hash unless format
|
38
38
|
|
39
|
-
hash = { "content" => hash }
|
40
|
-
hash["format"] = format
|
39
|
+
hash = { "content" => hash } unless hash.is_a? Hash
|
40
|
+
hash["format"] = format
|
41
41
|
hash
|
42
42
|
end
|
43
43
|
end
|
@@ -1,6 +1,11 @@
|
|
1
1
|
module RelatonBib
|
2
2
|
class HashConverter
|
3
3
|
class << self
|
4
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
5
|
+
|
6
|
+
# @param args [Hash]
|
7
|
+
# @param neated [TrueClas, FalseClass] default true
|
8
|
+
# @return [Hash]
|
4
9
|
def hash_to_bib(args, nested = false)
|
5
10
|
return nil unless args.is_a?(Hash)
|
6
11
|
|
@@ -18,6 +23,7 @@ module RelatonBib
|
|
18
23
|
formattedref_hash_to_bib(ret)
|
19
24
|
docstatus_hash_to_bib(ret)
|
20
25
|
contributors_hash_to_bib(ret)
|
26
|
+
copyright_hash_to_bib(ret)
|
21
27
|
relations_hash_to_bib(ret)
|
22
28
|
series_hash_to_bib(ret)
|
23
29
|
medium_hash_to_bib(ret)
|
@@ -28,8 +34,12 @@ module RelatonBib
|
|
28
34
|
validity_hash_to_bib(ret)
|
29
35
|
ret[:keyword] = array(ret[:keyword])
|
30
36
|
ret[:license] = array(ret[:license])
|
37
|
+
editorialgroup_hash_to_bib ret
|
38
|
+
ics_hash_to_bib ret
|
39
|
+
structuredidentifier_hash_to_bib ret
|
31
40
|
ret
|
32
41
|
end
|
42
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
33
43
|
|
34
44
|
def timestamp_hash(ret)
|
35
45
|
ret[:fetched] ||= Date.today.to_s
|
@@ -48,11 +58,12 @@ module RelatonBib
|
|
48
58
|
def title_hash_to_bib(ret)
|
49
59
|
return unless ret[:title]
|
50
60
|
|
51
|
-
ret[:title] = array(ret[:title])
|
52
|
-
|
53
|
-
if t.is_a?(Hash) then t
|
61
|
+
ret[:title] = array(ret[:title]).reduce([]) do |m, t|
|
62
|
+
if t.is_a?(Hash) then m << t
|
54
63
|
else
|
55
|
-
|
64
|
+
m + TypedTitleString.from_string(t)
|
65
|
+
# { content: t, language: "en", script: "Latn", format: "text/plain",
|
66
|
+
# type: "main" }
|
56
67
|
end
|
57
68
|
end
|
58
69
|
end
|
@@ -151,12 +162,21 @@ module RelatonBib
|
|
151
162
|
|
152
163
|
def docstatus_hash_to_bib(ret)
|
153
164
|
ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
|
154
|
-
stage: ret[:docstatus][:stage],
|
155
|
-
substage: ret[:docstatus][:substage],
|
165
|
+
stage: stage(ret[:docstatus][:stage]),
|
166
|
+
substage: stage(ret[:docstatus][:substage]),
|
156
167
|
iteration: ret[:docstatus][:iteration],
|
157
168
|
)
|
158
169
|
end
|
159
170
|
|
171
|
+
# @param stg [Hash]
|
172
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
173
|
+
def stage(stg)
|
174
|
+
return unless stg
|
175
|
+
|
176
|
+
args = stg.is_a?(String) ? { value: stg } : stg
|
177
|
+
DocumentStatus::Stage.new(**args)
|
178
|
+
end
|
179
|
+
|
160
180
|
def contributors_hash_to_bib(ret)
|
161
181
|
return unless ret[:contributor]
|
162
182
|
|
@@ -252,6 +272,16 @@ module RelatonBib
|
|
252
272
|
end
|
253
273
|
end
|
254
274
|
|
275
|
+
# @param ret [Hash]
|
276
|
+
def copyright_hash_to_bib(ret)
|
277
|
+
return unless ret[:copyright]
|
278
|
+
|
279
|
+
ret[:copyright] = array(ret[:copyright]).map do |c|
|
280
|
+
c[:owner] = array(c[:owner])
|
281
|
+
c
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
255
285
|
# @param ret [Hash]
|
256
286
|
def relations_hash_to_bib(ret)
|
257
287
|
return unless ret[:relation]
|
@@ -284,15 +314,16 @@ module RelatonBib
|
|
284
314
|
end
|
285
315
|
|
286
316
|
# @param rel [Hash] relation
|
317
|
+
# @return [RelatonBib::LocalityStack]
|
287
318
|
def relation_locality_hash_to_bib(rel)
|
288
319
|
rel[:locality] = array(rel[:locality])&.map do |bl|
|
289
320
|
ls = if bl[:locality_stack]
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
321
|
+
array(bl[:locality_stack]).map do |l|
|
322
|
+
Locality.new(l[:type], l[:reference_from], l[:reference_to])
|
323
|
+
end
|
324
|
+
else
|
325
|
+
[Locality.new(bl[:type], bl[:reference_from], bl[:reference_to])]
|
326
|
+
end
|
296
327
|
LocalityStack.new ls
|
297
328
|
end
|
298
329
|
end
|
@@ -311,11 +342,12 @@ module RelatonBib
|
|
311
342
|
end
|
312
343
|
end
|
313
344
|
|
345
|
+
# @param ret [Hash]
|
314
346
|
def series_hash_to_bib(ret)
|
315
347
|
ret[:series] = array(ret[:series])&.map do |s|
|
316
348
|
s[:formattedref] && s[:formattedref] = formattedref(s[:formattedref])
|
317
349
|
if s[:title]
|
318
|
-
s[:title] = { content: s[:title] } unless s.is_a?(Hash)
|
350
|
+
s[:title] = { content: s[:title] } unless s[:title].is_a?(Hash)
|
319
351
|
s[:title] = typed_title_strig(s[:title])
|
320
352
|
end
|
321
353
|
s[:abbreviation] && s[:abbreviation] = localizedstring(s[:abbreviation])
|
@@ -329,28 +361,60 @@ module RelatonBib
|
|
329
361
|
TypedTitleString.new title
|
330
362
|
end
|
331
363
|
|
364
|
+
# @param ret [Hash]
|
332
365
|
def medium_hash_to_bib(ret)
|
333
366
|
ret[:medium] = Medium.new(ret[:medium]) if ret[:medium]
|
334
367
|
end
|
335
368
|
|
369
|
+
# @param ret [Hash]
|
336
370
|
def classification_hash_to_bib(ret)
|
337
|
-
# ret[:classification] = [ret[:classification]] unless ret[:classification].is_a?(Array)
|
338
|
-
# ret[:classification]&.each_with_index do |c, i|
|
339
|
-
# ret[:classification][i] = RelatonBib::Classification.new(c)
|
340
|
-
# end
|
341
371
|
if ret[:classification]
|
342
|
-
ret[:classification] = array(ret[:classification]).map
|
372
|
+
ret[:classification] = array(ret[:classification]).map do |cls|
|
373
|
+
Classification.new cls
|
374
|
+
end
|
343
375
|
end
|
344
376
|
end
|
345
377
|
|
378
|
+
# rubocop:disable Metrics/AbcSize
|
379
|
+
|
380
|
+
# @param ret [Hash]
|
346
381
|
def validity_hash_to_bib(ret)
|
347
382
|
return unless ret[:validity]
|
348
383
|
|
349
|
-
ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins])
|
350
|
-
ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends])
|
351
|
-
ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision])
|
384
|
+
ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins].to_s)
|
385
|
+
ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends].to_s)
|
386
|
+
ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision].to_s)
|
352
387
|
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
|
353
388
|
end
|
389
|
+
# rubocop:enable Metrics/AbcSize
|
390
|
+
|
391
|
+
# @param ret [Hash]
|
392
|
+
def editorialgroup_hash_to_bib(ret)
|
393
|
+
return unless ret[:editorialgroup]
|
394
|
+
|
395
|
+
technical_committee = array(ret[:editorialgroup]).map do |wg|
|
396
|
+
TechnicalCommittee.new WorkGroup.new(wg)
|
397
|
+
end
|
398
|
+
ret[:editorialgroup] = EditorialGroup.new technical_committee
|
399
|
+
end
|
400
|
+
|
401
|
+
# @param ret [Hash]
|
402
|
+
def ics_hash_to_bib(ret)
|
403
|
+
return unless ret[:ics]
|
404
|
+
|
405
|
+
ret[:ics] = array(ret[:ics]).map { |ics| ICS.new ics }
|
406
|
+
end
|
407
|
+
|
408
|
+
# @param ret [Hash]
|
409
|
+
def structuredidentifier_hash_to_bib(ret)
|
410
|
+
return unless ret[:structuredidentifier]
|
411
|
+
|
412
|
+
sids = array(ret[:structuredidentifier]).map do |si|
|
413
|
+
si[:agency] = array si[:agency]
|
414
|
+
StructuredIdentifier.new si
|
415
|
+
end
|
416
|
+
ret[:structuredidentifier] = StructuredIdentifierCollection.new sids
|
417
|
+
end
|
354
418
|
|
355
419
|
# @param ogj [Hash, Array, String]
|
356
420
|
# @return [Hash, Array, String]
|
@@ -367,6 +431,8 @@ module RelatonBib
|
|
367
431
|
end
|
368
432
|
end
|
369
433
|
|
434
|
+
# @param arr [NilClass, Array, #is_a?]
|
435
|
+
# @return [Array]
|
370
436
|
def array(arr)
|
371
437
|
return [] unless arr
|
372
438
|
return [arr] unless arr.is_a?(Array)
|
@@ -374,6 +440,9 @@ module RelatonBib
|
|
374
440
|
arr
|
375
441
|
end
|
376
442
|
|
443
|
+
# @param name [Hash, String, NilClass]
|
444
|
+
# @param person [Hash]
|
445
|
+
# @return [RelatonBib::LocalizedString]
|
377
446
|
def localname(name, person)
|
378
447
|
return nil if name.nil?
|
379
448
|
|
@@ -381,13 +450,12 @@ module RelatonBib
|
|
381
450
|
lang ||= person[:name][:language]
|
382
451
|
script = name[:script] if name.is_a?(Hash)
|
383
452
|
script ||= person[:name][:script]
|
384
|
-
|
385
|
-
|
386
|
-
else
|
387
|
-
RelatonBib::LocalizedString.new(name, lang, script)
|
388
|
-
end
|
453
|
+
n = name.is_a?(Hash) ? name[:content] : name
|
454
|
+
RelatonBib::LocalizedString.new(n, lang, script)
|
389
455
|
end
|
390
456
|
|
457
|
+
# @param lst [Hash, Array<RelatonBib::LocalizedString>]
|
458
|
+
# @return [RelatonBib::LocalizedString]
|
391
459
|
def localizedstring(lst)
|
392
460
|
if lst.is_a?(Hash)
|
393
461
|
RelatonBib::LocalizedString.new(lst[:content], lst[:language], lst[:script])
|
@@ -396,6 +464,8 @@ module RelatonBib
|
|
396
464
|
end
|
397
465
|
end
|
398
466
|
|
467
|
+
# @param frf [Hash, String]
|
468
|
+
# @return [RelatonBib::FormattedRef]
|
399
469
|
def formattedref(frf)
|
400
470
|
if frf.is_a?(Hash)
|
401
471
|
RelatonBib::FormattedRef.new(frf)
|