relaton-bib 1.0.4 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/relaton_bib.rb +3 -3
- data/lib/relaton_bib/bibliographic_item.rb +9 -11
- data/lib/relaton_bib/copyright_association.rb +28 -9
- data/lib/relaton_bib/document_status.rb +3 -2
- data/lib/relaton_bib/hash_converter.rb +16 -4
- data/lib/relaton_bib/typed_title_string.rb +2 -8
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +15 -21
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f046b9f9c341d92cec95e89a817afea83133a322255f259c34c869aafcea60c
|
4
|
+
data.tar.gz: e9535bc5707436472ef9986faa9e429d2c451c94bc9b46f0ed10b21b8304dc41
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85b19d11a3eef57448df18fee645c53539fc485cf90f6b07b303311bf0d7dd2f4666c1bacfeae3f15aafc372cc93a60bfbcb3993783cba3103dd018633607633
|
7
|
+
data.tar.gz: 6a91bcba71ca9d070eb906a827ee8b5be314b888691e1f4849081163efc1c9e2b2218ac3d03e791569852cfa49ec9c2d1af7e8e16a45ff2facbf2af9b1c32824
|
data/lib/relaton_bib.rb
CHANGED
@@ -13,7 +13,8 @@ module RelatonBib
|
|
13
13
|
# @param date [String]
|
14
14
|
# @return [Date, NilClass]
|
15
15
|
def parse_date(sdate)
|
16
|
-
if
|
16
|
+
if sdate.is_a?(Date) then sdate
|
17
|
+
elsif /(?<date>\w+\s\d{4})/ =~ sdate # February 2012
|
17
18
|
Date.strptime(date, "%B %Y")
|
18
19
|
elsif /(?<date>\w+\s\d{1,2},\s\d{4})/ =~ sdate # February 11, 2012
|
19
20
|
Date.strptime(date, "%B %d, %Y")
|
@@ -21,8 +22,7 @@ module RelatonBib
|
|
21
22
|
Date.parse(date)
|
22
23
|
elsif /(?<date>\d{4}-\d{2})/ =~ sdate # 2012-02
|
23
24
|
Date.strptime date, "%Y-%m"
|
24
|
-
elsif /(?<date>\d{4})/ =~ sdate # 2012
|
25
|
-
Date.strptime date, "%Y"
|
25
|
+
elsif /(?<date>\d{4})/ =~ sdate then Date.strptime date, "%Y" # 2012
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
@@ -83,7 +83,7 @@ module RelatonBib
|
|
83
83
|
# @return [RelatonBib::DocumentStatus, NilClass]
|
84
84
|
attr_reader :status
|
85
85
|
|
86
|
-
# @return [RelatonBib::CopyrightAssociation
|
86
|
+
# @return [Array<RelatonBib::CopyrightAssociation>]
|
87
87
|
attr_reader :copyright
|
88
88
|
|
89
89
|
# @return [RelatonBib::DocRelationCollection]
|
@@ -141,10 +141,11 @@ module RelatonBib
|
|
141
141
|
# @param fetched [Date, NilClass] default nil
|
142
142
|
# @param keyword [Array<String>]
|
143
143
|
#
|
144
|
-
# @param copyright [Hash, RelatonBib::CopyrightAssociation
|
145
|
-
# @option copyright [Hash, RelatonBib::ContributionInfo] :owner
|
146
|
-
# @option copyright [String] :
|
144
|
+
# @param copyright [Array<Hash, RelatonBib::CopyrightAssociation>]
|
145
|
+
# @option copyright [Array<Hash, RelatonBib::ContributionInfo>] :owner
|
146
|
+
# @option copyright [String] :from
|
147
147
|
# @option copyright [String, NilClass] :to
|
148
|
+
# @option copyright [String, NilClass] :scope
|
148
149
|
#
|
149
150
|
# @param date [Array<Hash>]
|
150
151
|
# @option date [String] :type
|
@@ -202,11 +203,8 @@ module RelatonBib
|
|
202
203
|
a.is_a?(Hash) ? FormattedString.new(a) : a
|
203
204
|
end
|
204
205
|
|
205
|
-
|
206
|
-
|
207
|
-
CopyrightAssociation.new args[:copyright]
|
208
|
-
else args[:copyright]
|
209
|
-
end
|
206
|
+
@copyright = args.fetch(:copyright, []).map do |c|
|
207
|
+
c.is_a?(Hash) ? CopyrightAssociation.new(c) : c
|
210
208
|
end
|
211
209
|
|
212
210
|
@docidentifier = args[:docid] || []
|
@@ -308,7 +306,7 @@ module RelatonBib
|
|
308
306
|
hash["formattedref"] = formattedref.to_hash if formattedref
|
309
307
|
hash["abstract"] = single_element_array(abstract) if abstract&.any?
|
310
308
|
hash["docstatus"] = status.to_hash if status
|
311
|
-
hash["copyright"] = copyright
|
309
|
+
hash["copyright"] = single_element_array(copyright) if copyright&.any?
|
312
310
|
hash["relation"] = single_element_array(relation) if relation&.any?
|
313
311
|
hash["series"] = single_element_array(series) if series&.any?
|
314
312
|
hash["medium"] = medium.to_hash if medium
|
@@ -530,7 +528,7 @@ module RelatonBib
|
|
530
528
|
script.each { |s| builder.script s }
|
531
529
|
abstract.each { |a| builder.abstract { a.to_xml(builder) } }
|
532
530
|
status&.to_xml builder
|
533
|
-
copyright&.to_xml builder
|
531
|
+
copyright&.each { |c| c.to_xml builder }
|
534
532
|
relation.each { |r| r.to_xml builder, **opts }
|
535
533
|
series.each { |s| s.to_xml builder }
|
536
534
|
medium&.to_xml builder
|
@@ -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
|
@@ -5,10 +5,10 @@ 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]
|
@@ -44,6 +44,7 @@ module RelatonBib
|
|
44
44
|
private
|
45
45
|
|
46
46
|
# @param stg [RelatonBib::DocumentStatus::Stage, Hash, String, NilClass]
|
47
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
47
48
|
def stage_new(stg)
|
48
49
|
if stg.is_a?(Stage) then stg
|
49
50
|
elsif stg.is_a?(Hash) then Stage.new(stg)
|
@@ -23,6 +23,7 @@ module RelatonBib
|
|
23
23
|
formattedref_hash_to_bib(ret)
|
24
24
|
docstatus_hash_to_bib(ret)
|
25
25
|
contributors_hash_to_bib(ret)
|
26
|
+
copyright_hash_to_bib(ret)
|
26
27
|
relations_hash_to_bib(ret)
|
27
28
|
series_hash_to_bib(ret)
|
28
29
|
medium_hash_to_bib(ret)
|
@@ -58,7 +59,8 @@ module RelatonBib
|
|
58
59
|
ret[:title] = ret[:title].map do |t|
|
59
60
|
if t.is_a?(Hash) then t
|
60
61
|
else
|
61
|
-
{ content: t, language: "en", script: "Latn", format: "text/plain",
|
62
|
+
{ content: t, language: "en", script: "Latn", format: "text/plain",
|
63
|
+
type: "main" }
|
62
64
|
end
|
63
65
|
end
|
64
66
|
end
|
@@ -267,6 +269,16 @@ module RelatonBib
|
|
267
269
|
end
|
268
270
|
end
|
269
271
|
|
272
|
+
# @param ret [Hash]
|
273
|
+
def copyright_hash_to_bib(ret)
|
274
|
+
return unless ret[:copyright]
|
275
|
+
|
276
|
+
ret[:copyright] = array(ret[:copyright]).map do |c|
|
277
|
+
c[:owner] = array(c[:owner])
|
278
|
+
c
|
279
|
+
end
|
280
|
+
end
|
281
|
+
|
270
282
|
# @param ret [Hash]
|
271
283
|
def relations_hash_to_bib(ret)
|
272
284
|
return unless ret[:relation]
|
@@ -361,9 +373,9 @@ module RelatonBib
|
|
361
373
|
def validity_hash_to_bib(ret)
|
362
374
|
return unless ret[:validity]
|
363
375
|
|
364
|
-
ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins])
|
365
|
-
ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends])
|
366
|
-
ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision])
|
376
|
+
ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins].to_s)
|
377
|
+
ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends].to_s)
|
378
|
+
ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision].to_s)
|
367
379
|
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
|
368
380
|
end
|
369
381
|
|
@@ -1,14 +1,12 @@
|
|
1
1
|
module RelatonBib
|
2
2
|
class TypedTitleString
|
3
|
-
# TITLE_TYPES = %w[alternative original unofficial subtitle main].freeze
|
4
|
-
|
5
3
|
# @return [String]
|
6
4
|
attr_reader :type
|
7
5
|
|
8
6
|
# @return [RelatonBib::FormattedString]
|
9
7
|
attr_reader :title
|
10
8
|
|
11
|
-
# rubocop:disable Metrics/
|
9
|
+
# rubocop:disable Metrics/MethodLength
|
12
10
|
|
13
11
|
# @param type [String]
|
14
12
|
# @param title [RelatonBib::FormattedString, Hash]
|
@@ -16,10 +14,6 @@ module RelatonBib
|
|
16
14
|
# @param language [String]
|
17
15
|
# @param script [String]
|
18
16
|
def initialize(**args)
|
19
|
-
# if args[:type] && !TITLE_TYPES.include?(args[:type])
|
20
|
-
# warn %{[relaton-bib] title type "#{args[:type]}" is invalid.}
|
21
|
-
# end
|
22
|
-
|
23
17
|
unless args[:title] || args[:content]
|
24
18
|
raise ArgumentError, %{Keyword "title" or "content" should be passed.}
|
25
19
|
end
|
@@ -35,7 +29,7 @@ module RelatonBib
|
|
35
29
|
@title = FormattedString.new(fsargs)
|
36
30
|
end
|
37
31
|
end
|
38
|
-
# rubocop:enable Metrics/
|
32
|
+
# rubocop:enable Metrics/MethodLength
|
39
33
|
|
40
34
|
# @param builder [Nokogiri::XML::Builder]
|
41
35
|
def to_xml(builder)
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -244,14 +244,9 @@ module RelatonBib
|
|
244
244
|
end
|
245
245
|
|
246
246
|
cn = person.at "./name/completename"
|
247
|
-
cname =
|
248
|
-
LocalizedString.new(cn.text, cn[:language], cn[:script])
|
249
|
-
else
|
250
|
-
nil
|
251
|
-
end
|
252
|
-
|
247
|
+
cname = cn && LocalizedString.new(cn.text, cn[:language], cn[:script])
|
253
248
|
sn = person.at "./name/surname"
|
254
|
-
sname = sn
|
249
|
+
sname = sn && LocalizedString.new(sn.text, sn[:language], sn[:script])
|
255
250
|
|
256
251
|
name = FullName.new(
|
257
252
|
completename: cname, surname: sname,
|
@@ -291,25 +286,24 @@ module RelatonBib
|
|
291
286
|
# @return [Array<RelatonBib::FormattedString>]
|
292
287
|
def fetch_abstract(item)
|
293
288
|
item.xpath("./abstract").map do |a|
|
294
|
-
FormattedString.new(
|
295
|
-
|
296
|
-
)
|
289
|
+
FormattedString.new(content: a.text, language: a[:language],
|
290
|
+
script: a[:script], format: a[:format])
|
297
291
|
end
|
298
292
|
end
|
299
293
|
|
300
294
|
# @param item [Nokogiri::XML::Element]
|
301
|
-
# @return [RelatonBib::CopyrightAssociation]
|
295
|
+
# @return [Array<RelatonBib::CopyrightAssociation>]
|
302
296
|
def fetch_copyright(item)
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
297
|
+
item.xpath("./copyright").map do |cp|
|
298
|
+
owner = cp.xpath("owner").map do |o|
|
299
|
+
ContributionInfo.new entity: get_org(o.at("organization"))
|
300
|
+
end
|
301
|
+
from = cp.at("from")&.text
|
302
|
+
to = cp.at("to")&.text
|
303
|
+
scope = cp.at("scope")&.text
|
304
|
+
CopyrightAssociation.new(owner: owner, from: from, to: to,
|
305
|
+
scope: scope)
|
306
|
+
end
|
313
307
|
end
|
314
308
|
|
315
309
|
# @param item [Nokogiri::XML::Element]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: relaton-bib
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-06-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|