relaton-bib 1.0.2 → 1.0.3
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/document_relation.rb +10 -5
- data/lib/relaton_bib/document_status.rb +46 -8
- data/lib/relaton_bib/hash_converter.rb +16 -2
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +11 -3
- 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: bedb89ee8f076ed4e8425c31c97f6649944de4e3402e4cfb6747688ad63a9889
|
4
|
+
data.tar.gz: aa1391e5af6e07da77b848dfa0fc71be21b95ecd77972952ed922bcdf7ce59db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27d51cee453b3449681b498fffb6067f2366e9ceeb1525bf13c80ff13c12f39dbfb2158da0cbee60111d4623d7054fb5a8e22ad89edc18ee582f04fe5c3ae35a
|
7
|
+
data.tar.gz: 56ee00e29060d7f7eaccdbb8ac16b3c0d9186916583b28f5e01eaaadf6a42bc54b5ac3e8695e1f4d17eac5e202b6be53b6e0ed7ea6bfea0b277e01a73fc8c1e4
|
@@ -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]
|
@@ -14,12 +14,12 @@ module RelatonBib
|
|
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,56 @@ 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
|
+
def stage_new(stg)
|
48
|
+
if stg.is_a?(Stage) then stg
|
49
|
+
elsif stg.is_a?(Hash) then Stage.new(stg)
|
50
|
+
elsif stg.is_a?(String) then Stage.new(value: stg)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class Stage
|
55
|
+
# @return [String]
|
56
|
+
attr_reader :value
|
57
|
+
|
58
|
+
# @return [String, NilClass]
|
59
|
+
attr_reader :abbreviation
|
60
|
+
|
61
|
+
# @parma value [String]
|
62
|
+
# @param abbreviation [String, NilClass]
|
63
|
+
def initialize(value:, abbreviation: nil)
|
64
|
+
@value = value
|
65
|
+
@abbreviation = abbreviation
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Nokogiri::XML::Builder]
|
69
|
+
def to_xml(builder)
|
70
|
+
builder.parent[:abbreviation] = abbreviation if abbreviation
|
71
|
+
builder.text value
|
72
|
+
end
|
73
|
+
|
74
|
+
# @return [Hash]
|
75
|
+
def to_hash
|
76
|
+
hash = { "value" => value }
|
77
|
+
hash["abbreviation"] = abbreviation if abbreviation
|
78
|
+
hash
|
79
|
+
end
|
80
|
+
end
|
43
81
|
end
|
44
82
|
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
|
|
@@ -30,6 +35,7 @@ module RelatonBib
|
|
30
35
|
ret[:license] = array(ret[:license])
|
31
36
|
ret
|
32
37
|
end
|
38
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
33
39
|
|
34
40
|
def timestamp_hash(ret)
|
35
41
|
ret[:fetched] ||= Date.today.to_s
|
@@ -151,12 +157,20 @@ module RelatonBib
|
|
151
157
|
|
152
158
|
def docstatus_hash_to_bib(ret)
|
153
159
|
ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
|
154
|
-
stage: ret[:docstatus][:stage],
|
155
|
-
substage: ret[:docstatus][:substage],
|
160
|
+
stage: stage(ret[:docstatus][:stage]),
|
161
|
+
substage: stage(ret[:docstatus][:substage]),
|
156
162
|
iteration: ret[:docstatus][:iteration],
|
157
163
|
)
|
158
164
|
end
|
159
165
|
|
166
|
+
# @param stg [Hash]
|
167
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
168
|
+
def stage(stg)
|
169
|
+
return unless stg
|
170
|
+
|
171
|
+
DocumentStatus::Stage.new(**stg)
|
172
|
+
end
|
173
|
+
|
160
174
|
def contributors_hash_to_bib(ret)
|
161
175
|
return unless ret[:contributor]
|
162
176
|
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -169,14 +169,22 @@ module RelatonBib
|
|
169
169
|
status = item.at("./status")
|
170
170
|
return unless status
|
171
171
|
|
172
|
-
|
172
|
+
stg = status.at "stage"
|
173
173
|
DocumentStatus.new(
|
174
|
-
stage:
|
175
|
-
substage: status.at("substage")
|
174
|
+
stage: stg ? stage(stg) : status.text,
|
175
|
+
substage: stage(status.at("substage")),
|
176
176
|
iteration: status.at("iteration")&.text,
|
177
177
|
)
|
178
178
|
end
|
179
179
|
|
180
|
+
# @param node [Nokogiri::XML::Elemen]
|
181
|
+
# @return [RelatonBib::DocumentStatus::Stage]
|
182
|
+
def stage(elm)
|
183
|
+
return unless elm
|
184
|
+
|
185
|
+
DocumentStatus::Stage.new value: elm.text, abbreviation: elm[:abbreviation]
|
186
|
+
end
|
187
|
+
|
180
188
|
def fetch_dates(item)
|
181
189
|
item.xpath("./date").reduce([]) do |a, d|
|
182
190
|
type = d[:type].to_s.empty? ? "published" : d[:type]
|
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.0.3
|
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-05-
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: debase
|