relaton-bib 0.3.6 → 0.3.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/macos.yml +27 -0
- data/.github/workflows/ubuntu.yml +27 -0
- data/.github/workflows/windows.yml +30 -0
- data/Gemfile.lock +1 -1
- data/docs/hash.adoc +9 -9
- data/lib/relaton_bib/biblio_version.rb +1 -1
- data/lib/relaton_bib/bibliographic_date.rb +2 -3
- data/lib/relaton_bib/bibliographic_item.rb +12 -1
- data/lib/relaton_bib/formatted_string.rb +2 -2
- data/lib/relaton_bib/hash_converter.rb +136 -91
- data/lib/relaton_bib/hit.rb +1 -1
- data/lib/relaton_bib/hit_collection.rb +1 -1
- data/lib/relaton_bib/typed_title_string.rb +10 -3
- data/lib/relaton_bib/typed_uri.rb +1 -1
- data/lib/relaton_bib/version.rb +1 -1
- data/lib/relaton_bib/xml_parser.rb +17 -6
- metadata +6 -6
- data/.travis.yml +0 -18
- data/appveyor.yml +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 036777d6efe6a40b3f0ec2e6c1e1acfaf793d556cbaf907f330ee867716dc5b8
|
4
|
+
data.tar.gz: c16adf3cedb42c0521266792c1fefbdae2081a3a5561dda64fa373965e24f225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f03693eca920a087d1a0e1f7d2ff0d30a69e4a70fabc4a68f2ce92dff39a091e871eb9dbdf51cbd637af12b7b88ab0b0ce8000cf8dd7e78e7ca76b0d788c23ad
|
7
|
+
data.tar.gz: 571a1e896ad96a4b7c76a32c12596694ea8528c91fab2a14c5d93106dd4c8f10ae73823fee8e5c6123a8e0a095ae6bb1425234e52cce21268dc503cb108e62f7
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: macos
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-macos:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} macOS
|
10
|
+
runs-on: macos-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
run: |
|
23
|
+
sudo gem install bundler -v "~> 2" --force
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
- name: Run specs
|
26
|
+
run: |
|
27
|
+
bundle exec rake
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: ubuntu
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-linux:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} Ubuntu
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
run: |
|
23
|
+
gem install bundler -v "~> 2"
|
24
|
+
bundle install --jobs 4 --retry 3
|
25
|
+
- name: Run specs
|
26
|
+
run: |
|
27
|
+
bundle exec rake
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Auto-generated !!! Do not edit it manually
|
2
|
+
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
+
name: windows
|
4
|
+
|
5
|
+
on: [push]
|
6
|
+
|
7
|
+
jobs:
|
8
|
+
test-windows:
|
9
|
+
name: Test on Ruby ${{ matrix.ruby }} Windows
|
10
|
+
runs-on: windows-latest
|
11
|
+
strategy:
|
12
|
+
matrix:
|
13
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
14
|
+
steps:
|
15
|
+
- uses: actions/checkout@master
|
16
|
+
- name: Use Ruby
|
17
|
+
uses: actions/setup-ruby@v1
|
18
|
+
with:
|
19
|
+
ruby-version: ${{ matrix.ruby }}
|
20
|
+
architecture: 'x64'
|
21
|
+
- name: Update gems
|
22
|
+
shell: pwsh
|
23
|
+
run: |
|
24
|
+
gem install bundler -v "~> 2"
|
25
|
+
bundle config --local path vendor/bundle
|
26
|
+
bundle update
|
27
|
+
bundle install --jobs 4 --retry 3
|
28
|
+
- name: Run specs
|
29
|
+
run: |
|
30
|
+
bundle exec rake
|
data/Gemfile.lock
CHANGED
data/docs/hash.adoc
CHANGED
@@ -273,7 +273,7 @@ for the entry, the subclause title should be left as `{blank}`.
|
|
273
273
|
|
274
274
|
So the following is a very simple reference in Metanorma Asciidoctor:
|
275
275
|
|
276
|
-
[source,
|
276
|
+
[source,asciidoc]
|
277
277
|
----
|
278
278
|
[%bibitem]
|
279
279
|
=== Rubber latex -- Sampling
|
@@ -291,7 +291,7 @@ The anchor crossreference for the bibliographic entry may be encoded as the
|
|
291
291
|
`id` entry in the definition list, or as the normal Asciidoctor anchor on the
|
292
292
|
subclause, which takes priority over it:
|
293
293
|
|
294
|
-
[source,
|
294
|
+
[source,asciidoc]
|
295
295
|
----
|
296
296
|
[[iso123]]
|
297
297
|
[%bibitem]
|
@@ -306,7 +306,7 @@ Asciidoctor does not currently cope with definition lists more than four levels
|
|
306
306
|
deep. If deeper nesting is needed, you will need to attach a new definition
|
307
307
|
list with a list continuation:
|
308
308
|
|
309
|
-
[source,
|
309
|
+
[source,asciidoc]
|
310
310
|
----
|
311
311
|
[[iso123]]
|
312
312
|
[%bibitem]
|
@@ -555,7 +555,7 @@ The foregoing structure requires frequent breakouts into open blocks, to deal
|
|
555
555
|
with the limitation on Asciidoctor nested definition lists. An alternative is to
|
556
556
|
represent the nested structure of Relaton records in a simple, one-level definition list, and to use the key for each key-value pair to represent the hierarchical nesting of entries, as a dot-delimited path of keys. For example,
|
557
557
|
|
558
|
-
[source,
|
558
|
+
[source,asciidoc]
|
559
559
|
----
|
560
560
|
[%bibitem]
|
561
561
|
=== Rubber latex -- Sampling
|
@@ -567,7 +567,7 @@ docid::
|
|
567
567
|
|
568
568
|
can instead be represented as:
|
569
569
|
|
570
|
-
[source,
|
570
|
+
[source,asciidoc]
|
571
571
|
----
|
572
572
|
[%bibitem]
|
573
573
|
=== Rubber latex -- Sampling
|
@@ -578,7 +578,7 @@ docid.id::: ISO 123
|
|
578
578
|
|
579
579
|
Whenever part of the key is repeated between entries, the entries are assumed to attach to the same parent. If an array of hashes is needed, a blank entry is required for the key of each repeating element: For example,
|
580
580
|
|
581
|
-
[source,
|
581
|
+
[source,asciidoc]
|
582
582
|
----
|
583
583
|
[%bibitem]
|
584
584
|
=== Rubber latex -- Sampling
|
@@ -594,7 +594,7 @@ type:: standard
|
|
594
594
|
|
595
595
|
can instead be represented as:
|
596
596
|
|
597
|
-
[source,
|
597
|
+
[source,asciidoc]
|
598
598
|
----
|
599
599
|
[%bibitem]
|
600
600
|
=== Rubber latex -- Sampling
|
@@ -609,7 +609,7 @@ docid.id:: 32784
|
|
609
609
|
|
610
610
|
Embedded elements can also repeat:
|
611
611
|
|
612
|
-
[source,
|
612
|
+
[source,asciidoc]
|
613
613
|
----
|
614
614
|
[%bibitem]
|
615
615
|
...
|
@@ -629,7 +629,7 @@ person::
|
|
629
629
|
|
630
630
|
can instead be represented as:
|
631
631
|
|
632
|
-
[source,
|
632
|
+
[source,asciidoc]
|
633
633
|
----
|
634
634
|
[%bibitem]
|
635
635
|
...
|
@@ -20,7 +20,7 @@ module RelatonBib
|
|
20
20
|
# @param builder [Nokogiri::XML::Builder]
|
21
21
|
def to_xml(builder)
|
22
22
|
builder.version do
|
23
|
-
builder.
|
23
|
+
builder.send("revision-date", revision_date) if revision_date
|
24
24
|
draft.each { |d| builder.draft d }
|
25
25
|
end
|
26
26
|
end
|
@@ -6,8 +6,7 @@ module RelatonBib
|
|
6
6
|
# Bibliographic date.
|
7
7
|
class BibliographicDate
|
8
8
|
TYPES = %w[published accessed created implemented obsoleted confirmed
|
9
|
-
updated issued transmitted copied unchanged circulated
|
10
|
-
].freeze
|
9
|
+
updated issued transmitted copied unchanged circulated adapted].freeze
|
11
10
|
|
12
11
|
# @return [String]
|
13
12
|
attr_reader :type
|
@@ -28,7 +27,7 @@ module RelatonBib
|
|
28
27
|
def initialize(type:, on: nil, from: nil, to: nil)
|
29
28
|
raise ArgumentError, "expected :on or :from argument" unless on || from
|
30
29
|
|
31
|
-
raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
|
30
|
+
# raise ArgumentError, "invalid type: #{type}" unless TYPES.include? type
|
32
31
|
|
33
32
|
@type = type
|
34
33
|
@on = RelatonBib.parse_date on
|
@@ -169,7 +169,7 @@ module RelatonBib
|
|
169
169
|
# @option link [String] :content
|
170
170
|
def initialize(**args)
|
171
171
|
if args[:type] && !TYPES.include?(args[:type])
|
172
|
-
|
172
|
+
warn %{Document type "#{args[:type]}" is invalid.}
|
173
173
|
end
|
174
174
|
|
175
175
|
@title = (args[:title] || []).map do |t|
|
@@ -284,6 +284,7 @@ module RelatonBib
|
|
284
284
|
hash["contributor"] = single_element_array(contributor) if contributor&.any?
|
285
285
|
hash["edition"] = edition if edition
|
286
286
|
hash["version"] = version.to_hash if version
|
287
|
+
hash["revdate"] = revdate if revdate
|
287
288
|
hash["biblionote"] = single_element_array(biblionote) if biblionote&.any?
|
288
289
|
hash["language"] = single_element_array(language) if language&.any?
|
289
290
|
hash["script"] = single_element_array(script) if script&.any?
|
@@ -303,6 +304,16 @@ module RelatonBib
|
|
303
304
|
hash
|
304
305
|
end
|
305
306
|
|
307
|
+
# If revision_date exists then returns it else returns published date or nil
|
308
|
+
# @return [String, NilClass]
|
309
|
+
def revdate
|
310
|
+
@revdate ||= if version&.revision_date
|
311
|
+
version.revision_date
|
312
|
+
else
|
313
|
+
date.detect { |d| d.type == "published" }&.on&.to_s
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
306
317
|
private
|
307
318
|
|
308
319
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
@@ -13,8 +13,8 @@ module RelatonBib
|
|
13
13
|
attr_reader :format
|
14
14
|
|
15
15
|
# @param content [String]
|
16
|
-
# @param language [String] language code Iso639
|
17
|
-
# @param script [String] script code Iso15924
|
16
|
+
# @param language [String, NilClass] language code Iso639
|
17
|
+
# @param script [String, NilClass] script code Iso15924
|
18
18
|
# @param format [String] the content type
|
19
19
|
def initialize(content:, language: nil, script: nil, format: "text/plain")
|
20
20
|
# if format && !FORMATS.include?(format)
|
@@ -35,6 +35,7 @@ module RelatonBib
|
|
35
35
|
|
36
36
|
def extent_hash_to_bib(ret)
|
37
37
|
return unless ret[:extent]
|
38
|
+
|
38
39
|
ret[:extent] = array(ret[:extent])
|
39
40
|
ret[:extent]&.each_with_index do |e, i|
|
40
41
|
ret[:extent][i] = BibItemLocality.new(e[:type], e[:reference_from],
|
@@ -44,45 +45,57 @@ module RelatonBib
|
|
44
45
|
|
45
46
|
def title_hash_to_bib(ret)
|
46
47
|
return unless ret[:title]
|
48
|
+
|
47
49
|
ret[:title] = array(ret[:title])
|
48
50
|
ret[:title] = ret[:title].map do |t|
|
49
|
-
t.is_a?(Hash)
|
50
|
-
|
51
|
+
if t.is_a?(Hash) then t
|
52
|
+
else
|
53
|
+
{ content: t, language: "en", script: "Latn", format: "text/plain", type: "main" }
|
54
|
+
end
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
54
58
|
def language_hash_to_bib(ret)
|
55
59
|
return unless ret[:language]
|
60
|
+
|
56
61
|
ret[:language] = array(ret[:language])
|
57
62
|
end
|
58
63
|
|
59
64
|
def script_hash_to_bib(ret)
|
60
65
|
return unless ret[:script]
|
66
|
+
|
61
67
|
ret[:script] = array(ret[:script])
|
62
68
|
end
|
63
69
|
|
64
70
|
def abstract_hash_to_bib(ret)
|
65
71
|
return unless ret[:abstract]
|
66
|
-
|
72
|
+
|
73
|
+
ret[:abstract] = array(ret[:abstract]).map do |a|
|
74
|
+
a.is_a?(String) ? FormattedString.new(content: a) : a
|
75
|
+
end
|
67
76
|
end
|
68
77
|
|
69
78
|
def link_hash_to_bib(ret)
|
70
79
|
return unless ret[:link]
|
80
|
+
|
71
81
|
ret[:link] = array(ret[:link])
|
72
82
|
end
|
73
83
|
|
74
84
|
def place_hash_to_bib(ret)
|
75
85
|
return unless ret[:place]
|
86
|
+
|
76
87
|
ret[:place] = array(ret[:place])
|
77
88
|
end
|
78
89
|
|
79
90
|
def accesslocation_hash_to_bib(ret)
|
80
91
|
return unless ret[:accesslocation]
|
92
|
+
|
81
93
|
ret[:accesslocation] = array(ret[:accesslocation])
|
82
94
|
end
|
83
95
|
|
84
96
|
def dates_hash_to_bib(ret)
|
85
97
|
return unless ret[:date]
|
98
|
+
|
86
99
|
ret[:date] = array(ret[:date])
|
87
100
|
ret[:date].each_with_index do |d, i|
|
88
101
|
# value is synonym of on: it is reserved word in YAML
|
@@ -95,6 +108,7 @@ module RelatonBib
|
|
95
108
|
|
96
109
|
def docid_hash_to_bib(ret)
|
97
110
|
return unless ret[:docid]
|
111
|
+
|
98
112
|
ret[:docid] = array(ret[:docid])
|
99
113
|
ret[:docid]&.each_with_index do |id, i|
|
100
114
|
ret[:docid][i] = DocumentIdentifier.new(id: id[:id], type: id[:type])
|
@@ -103,32 +117,35 @@ module RelatonBib
|
|
103
117
|
|
104
118
|
def version_hash_to_bib(ret)
|
105
119
|
return unless ret[:version]
|
120
|
+
|
106
121
|
ret[:version][:draft] = array(ret[:version][:draft])
|
107
|
-
ret[:version]
|
108
|
-
|
122
|
+
ret[:version] && ret[:version] = BibliographicItem::Version.new(
|
123
|
+
ret[:version][:revision_date], ret[:version][:draft]
|
124
|
+
)
|
109
125
|
end
|
110
126
|
|
111
127
|
def biblionote_hash_to_bib(ret)
|
112
128
|
return unless ret[:biblionote]
|
129
|
+
|
113
130
|
ret[:biblionote] = array(ret[:biblionote])
|
114
131
|
(ret[:biblionote])&.each_with_index do |n, i|
|
115
|
-
ret[:biblionote][i] =
|
116
|
-
|
117
|
-
|
118
|
-
|
132
|
+
ret[:biblionote][i] = BiblioNote.new(
|
133
|
+
content: n[:content], type: n[:type], language: n[:language],
|
134
|
+
script: n[:script], format: n[:format]
|
135
|
+
)
|
119
136
|
end
|
120
137
|
end
|
121
138
|
|
122
139
|
def formattedref_hash_to_bib(ret)
|
123
|
-
ret[:formattedref]
|
124
|
-
formattedref(ret[:formattedref])
|
140
|
+
ret[:formattedref] && ret[:formattedref] = formattedref(ret[:formattedref])
|
125
141
|
end
|
126
142
|
|
127
143
|
def docstatus_hash_to_bib(ret)
|
128
|
-
ret[:docstatus]
|
129
|
-
|
130
|
-
|
131
|
-
|
144
|
+
ret[:docstatus] && ret[:docstatus] = DocumentStatus.new(
|
145
|
+
stage: ret[:docstatus][:stage],
|
146
|
+
substage: ret[:docstatus][:substage],
|
147
|
+
iteration: ret[:docstatus][:iteration],
|
148
|
+
)
|
132
149
|
end
|
133
150
|
|
134
151
|
def contributors_hash_to_bib(ret)
|
@@ -146,73 +163,83 @@ module RelatonBib
|
|
146
163
|
end
|
147
164
|
end
|
148
165
|
ret[:contributor][i][:role] = roles
|
149
|
-
ret[:contributor][i][:entity] = c[:person]
|
150
|
-
|
166
|
+
ret[:contributor][i][:entity] = if c[:person]
|
167
|
+
person_hash_to_bib(c[:person])
|
168
|
+
else
|
169
|
+
org_hash_to_bib(c[:organization])
|
170
|
+
end
|
151
171
|
ret[:contributor][i].delete(:person)
|
152
172
|
ret[:contributor][i].delete(:organization)
|
153
173
|
end
|
154
174
|
end
|
155
175
|
|
156
|
-
def org_hash_to_bib(
|
157
|
-
return nil if
|
158
|
-
|
176
|
+
def org_hash_to_bib(org)
|
177
|
+
return nil if org.nil?
|
178
|
+
|
179
|
+
org[:identifier] = array(org[:identifier])&.map do |a|
|
159
180
|
OrgIdentifier.new(a[:type], a[:id])
|
160
181
|
end
|
161
|
-
|
182
|
+
org
|
162
183
|
end
|
163
184
|
|
164
|
-
def person_hash_to_bib(
|
185
|
+
def person_hash_to_bib(person)
|
165
186
|
Person.new(
|
166
|
-
name: fullname_hash_to_bib(
|
167
|
-
affiliation: affiliation_hash_to_bib(
|
168
|
-
contact: contacts_hash_to_bib(
|
169
|
-
identifier: person_identifiers_hash_to_bib(
|
187
|
+
name: fullname_hash_to_bib(person),
|
188
|
+
affiliation: affiliation_hash_to_bib(person),
|
189
|
+
contact: contacts_hash_to_bib(person),
|
190
|
+
identifier: person_identifiers_hash_to_bib(person),
|
170
191
|
)
|
171
192
|
end
|
172
193
|
|
173
|
-
def fullname_hash_to_bib(
|
174
|
-
n =
|
194
|
+
def fullname_hash_to_bib(person)
|
195
|
+
n = person[:name]
|
175
196
|
FullName.new(
|
176
|
-
forename: array(n[:forename])&.map { |f| localname(f,
|
177
|
-
initial: array(n[:initial])&.map { |f| localname(f,
|
178
|
-
addition: array(n[:addition])&.map { |f| localname(f,
|
179
|
-
prefix: array(n[:prefix])&.map { |f| localname(f,
|
180
|
-
surname: localname(n[:surname],
|
181
|
-
completename: localname(n[:completename],
|
197
|
+
forename: array(n[:forename])&.map { |f| localname(f, person) },
|
198
|
+
initial: array(n[:initial])&.map { |f| localname(f, person) },
|
199
|
+
addition: array(n[:addition])&.map { |f| localname(f, person) },
|
200
|
+
prefix: array(n[:prefix])&.map { |f| localname(f, person) },
|
201
|
+
surname: localname(n[:surname], person),
|
202
|
+
completename: localname(n[:completename], person),
|
182
203
|
)
|
183
204
|
end
|
184
205
|
|
185
|
-
def person_identifiers_hash_to_bib(
|
186
|
-
array(
|
206
|
+
def person_identifiers_hash_to_bib(person)
|
207
|
+
array(person[:identifier])&.map do |a|
|
187
208
|
PersonIdentifier.new(a[:type], a[:id])
|
188
209
|
end
|
189
210
|
end
|
190
211
|
|
191
|
-
def affiliation_hash_to_bib(
|
192
|
-
return [] unless
|
193
|
-
|
212
|
+
def affiliation_hash_to_bib(person)
|
213
|
+
return [] unless person[:affiliation]
|
214
|
+
|
215
|
+
array(person[:affiliation]).map do |a|
|
194
216
|
a[:description] = array(a[:description])&.map do |d|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
217
|
+
cnt = if d.is_a?(Hash)
|
218
|
+
{ content: d[:content], language: d[:language],
|
219
|
+
script: d[:script], format: d[:format] }
|
220
|
+
else { content: d }
|
221
|
+
end
|
222
|
+
FormattedString.new cnt
|
200
223
|
end
|
201
224
|
Affilation.new(
|
202
225
|
organization: Organization.new(org_hash_to_bib(a[:organization])),
|
203
|
-
description: a[:description]
|
226
|
+
description: a[:description],
|
204
227
|
)
|
205
228
|
end
|
206
229
|
end
|
207
230
|
|
208
|
-
def contacts_hash_to_bib(
|
209
|
-
return [] unless
|
210
|
-
|
211
|
-
|
231
|
+
def contacts_hash_to_bib(person)
|
232
|
+
return [] unless person[:contact]
|
233
|
+
|
234
|
+
array(person[:contact]).map do |a|
|
235
|
+
if a[:city] || a[:country]
|
212
236
|
RelatonBib::Address.new(
|
213
237
|
street: Array(a[:street]), city: a[:city], postcode: a[:postcode],
|
214
|
-
country: a[:country], state: a[:state]
|
215
|
-
|
238
|
+
country: a[:country], state: a[:state]
|
239
|
+
)
|
240
|
+
else
|
241
|
+
RelatonBib::Contact.new(type: a[:type], value: a[:value])
|
242
|
+
end
|
216
243
|
end
|
217
244
|
end
|
218
245
|
|
@@ -227,14 +254,14 @@ module RelatonBib
|
|
227
254
|
end
|
228
255
|
|
229
256
|
# @param ret [Hash]
|
230
|
-
# @param
|
231
|
-
# @param
|
232
|
-
def relation_bibitem_hash_to_bib(ret,
|
233
|
-
if
|
234
|
-
ret[:relation][
|
257
|
+
# @param rel [Hash] relation
|
258
|
+
# @param idx [Integr] index of relation
|
259
|
+
def relation_bibitem_hash_to_bib(ret, rel, idx)
|
260
|
+
if rel[:bibitem]
|
261
|
+
ret[:relation][idx][:bibitem] = bib_item(hash_to_bib(rel[:bibitem], true))
|
235
262
|
else
|
236
|
-
warn "bibitem missing: #{
|
237
|
-
ret[:relation][
|
263
|
+
warn "bibitem missing: #{rel}"
|
264
|
+
ret[:relation][idx][:bibitem] = nil
|
238
265
|
end
|
239
266
|
end
|
240
267
|
|
@@ -244,9 +271,9 @@ module RelatonBib
|
|
244
271
|
BibliographicItem.new(item)
|
245
272
|
end
|
246
273
|
|
247
|
-
def relation_biblocality_hash_to_bib(ret,
|
248
|
-
ret[:relation][
|
249
|
-
array(
|
274
|
+
def relation_biblocality_hash_to_bib(ret, rel, idx)
|
275
|
+
ret[:relation][idx][:bib_locality] =
|
276
|
+
array(rel[:bib_locality])&.map do |bl|
|
250
277
|
BibItemLocality.new(bl[:type], bl[:reference_from],
|
251
278
|
bl[:reference_to])
|
252
279
|
end
|
@@ -271,7 +298,7 @@ module RelatonBib
|
|
271
298
|
end
|
272
299
|
|
273
300
|
def medium_hash_to_bib(ret)
|
274
|
-
ret[:medium]
|
301
|
+
ret[:medium] = Medium.new(ret[:medium]) if ret[:medium]
|
275
302
|
end
|
276
303
|
|
277
304
|
def classification_hash_to_bib(ret)
|
@@ -279,52 +306,70 @@ module RelatonBib
|
|
279
306
|
# ret[:classification]&.each_with_index do |c, i|
|
280
307
|
# ret[:classification][i] = RelatonBib::Classification.new(c)
|
281
308
|
# end
|
282
|
-
ret[:classification]
|
309
|
+
if ret[:classification]
|
283
310
|
ret[:classification] = Classification.new(ret[:classification])
|
311
|
+
end
|
284
312
|
end
|
285
313
|
|
286
314
|
def validity_hash_to_bib(ret)
|
287
315
|
return unless ret[:validity]
|
288
|
-
|
289
|
-
ret[:validity][:
|
290
|
-
ret[:validity][:
|
316
|
+
|
317
|
+
ret[:validity][:begins] && b = Time.parse(ret[:validity][:begins])
|
318
|
+
ret[:validity][:ends] && e = Time.parse(ret[:validity][:ends])
|
319
|
+
ret[:validity][:revision] && r = Time.parse(ret[:validity][:revision])
|
291
320
|
ret[:validity] = Validity.new(begins: b, ends: e, revision: r)
|
292
321
|
end
|
293
322
|
|
323
|
+
# @param ogj [Hash, Array, String]
|
324
|
+
# @return [Hash, Array, String]
|
294
325
|
def symbolize(obj)
|
295
|
-
obj.is_a? Hash
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
326
|
+
if obj.is_a? Hash
|
327
|
+
obj.reduce({}) do |memo, (k, v)|
|
328
|
+
memo[k.to_sym] = symbolize(v)
|
329
|
+
memo
|
330
|
+
end
|
331
|
+
elsif obj.is_a? Array
|
332
|
+
obj.reduce([]) { |memo, v| memo << symbolize(v) }
|
333
|
+
else
|
334
|
+
obj
|
335
|
+
end
|
300
336
|
end
|
301
337
|
|
302
|
-
def array(
|
303
|
-
return [] unless
|
304
|
-
return [
|
305
|
-
|
338
|
+
def array(arr)
|
339
|
+
return [] unless arr
|
340
|
+
return [arr] unless arr.is_a?(Array)
|
341
|
+
|
342
|
+
arr
|
306
343
|
end
|
307
344
|
|
308
|
-
def localname(
|
309
|
-
return nil if
|
310
|
-
|
311
|
-
lang
|
312
|
-
|
313
|
-
script
|
314
|
-
|
315
|
-
|
316
|
-
RelatonBib::LocalizedString.new(
|
345
|
+
def localname(name, person)
|
346
|
+
return nil if name.nil?
|
347
|
+
|
348
|
+
lang = name[:language] if name.is_a?(Hash)
|
349
|
+
lang ||= person[:name][:language]
|
350
|
+
script = name[:script] if name.is_a?(Hash)
|
351
|
+
script ||= person[:name][:script]
|
352
|
+
if name.is_a?(Hash)
|
353
|
+
RelatonBib::LocalizedString.new(name[:content], lang, script)
|
354
|
+
else
|
355
|
+
RelatonBib::LocalizedString.new(name, lang, script)
|
356
|
+
end
|
317
357
|
end
|
318
358
|
|
319
|
-
def localizedstring(
|
320
|
-
|
321
|
-
RelatonBib::LocalizedString.new(
|
322
|
-
|
359
|
+
def localizedstring(lst)
|
360
|
+
if lst.is_a?(Hash)
|
361
|
+
RelatonBib::LocalizedString.new(lst[:content], lst[:language], lst[:script])
|
362
|
+
else
|
363
|
+
RelatonBib::LocalizedString.new(lst)
|
364
|
+
end
|
323
365
|
end
|
324
366
|
|
325
|
-
def formattedref(
|
326
|
-
|
327
|
-
RelatonBib::FormattedRef.new(
|
367
|
+
def formattedref(frf)
|
368
|
+
if frf.is_a?(Hash)
|
369
|
+
RelatonBib::FormattedRef.new(frf)
|
370
|
+
else
|
371
|
+
RelatonBib::FormattedRef.new(content: frf)
|
372
|
+
end
|
328
373
|
end
|
329
374
|
end
|
330
375
|
end
|
data/lib/relaton_bib/hit.rb
CHANGED
@@ -4,7 +4,7 @@ module RelatonBib
|
|
4
4
|
attr_reader :hit
|
5
5
|
|
6
6
|
# @param hit [Hash]
|
7
|
-
# @param hit_collection [RelatonNist:HitCollection]
|
7
|
+
# @param hit_collection [RelatonIso::HitCollection, RelatonNist:HitCollection]
|
8
8
|
def initialize(hit, hit_collection = nil)
|
9
9
|
@hit = hit
|
10
10
|
@hit_collection = hit_collection
|
@@ -45,9 +45,16 @@ module RelatonBib
|
|
45
45
|
|
46
46
|
# @return [Hash]
|
47
47
|
def to_hash
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
th = title.to_hash
|
49
|
+
return th unless type
|
50
|
+
|
51
|
+
hash = { "type" => type }
|
52
|
+
if th.is_a? String
|
53
|
+
hash["content"] = th
|
54
|
+
else
|
55
|
+
hash.merge! th
|
56
|
+
end
|
57
|
+
hash
|
51
58
|
end
|
52
59
|
end
|
53
60
|
end
|
data/lib/relaton_bib/version.rb
CHANGED
@@ -5,7 +5,8 @@ module RelatonBib
|
|
5
5
|
class << self
|
6
6
|
def from_xml(xml)
|
7
7
|
doc = Nokogiri::XML(xml)
|
8
|
-
|
8
|
+
doc.remove_namespaces!
|
9
|
+
bibitem = doc.at "/bibitem|/bibdata"
|
9
10
|
BibliographicItem.new(item_data(bibitem))
|
10
11
|
end
|
11
12
|
|
@@ -29,8 +30,8 @@ module RelatonBib
|
|
29
30
|
edition: bibitem.at("./edition")&.text,
|
30
31
|
version: fetch_version(bibitem),
|
31
32
|
biblionote: fetch_note(bibitem),
|
32
|
-
language: bibitem
|
33
|
-
script: bibitem
|
33
|
+
language: fetch_language(bibitem),
|
34
|
+
script: fetch_script(bibitem),
|
34
35
|
abstract: fetch_abstract(bibitem),
|
35
36
|
docstatus: fetch_status(bibitem),
|
36
37
|
copyright: fetch_copyright(bibitem),
|
@@ -50,7 +51,7 @@ module RelatonBib
|
|
50
51
|
version = item.at "./version"
|
51
52
|
return unless version
|
52
53
|
|
53
|
-
revision_date = version.at("
|
54
|
+
revision_date = version.at("revision-date")&.text
|
54
55
|
draft = version.xpath("draft").map &:text
|
55
56
|
RelatonBib::BibliographicItem::Version.new revision_date, draft
|
56
57
|
end
|
@@ -67,6 +68,14 @@ module RelatonBib
|
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
71
|
+
def fetch_language(item)
|
72
|
+
item.xpath("./language").reduce([]) { |a, l| l.text.empty? ? a : a << l.text }
|
73
|
+
end
|
74
|
+
|
75
|
+
def fetch_script(item)
|
76
|
+
item.xpath("./script").reduce([]) { |a, s| s.text.empty? ? a : a << s.text }
|
77
|
+
end
|
78
|
+
|
70
79
|
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
71
80
|
|
72
81
|
def fetch_series(item)
|
@@ -145,8 +154,9 @@ module RelatonBib
|
|
145
154
|
status = item.at("./status")
|
146
155
|
return unless status
|
147
156
|
|
157
|
+
stage = status.at "stage"
|
148
158
|
DocumentStatus.new(
|
149
|
-
stage:
|
159
|
+
stage: stage ? stage.text : status.text,
|
150
160
|
substage: status.at("substage")&.text,
|
151
161
|
iteration: status.at("iteration")&.text,
|
152
162
|
)
|
@@ -154,8 +164,9 @@ module RelatonBib
|
|
154
164
|
|
155
165
|
def fetch_dates(item)
|
156
166
|
item.xpath("./date").map do |d|
|
167
|
+
type = d[:type].to_s.empty? ? "published" : d[:type]
|
157
168
|
RelatonBib::BibliographicDate.new(
|
158
|
-
type:
|
169
|
+
type: type, on: d.at("on")&.text, from: d.at("from")&.text,
|
159
170
|
to: d.at("to")&.text
|
160
171
|
)
|
161
172
|
end
|
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: 0.3.
|
4
|
+
version: 0.3.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -157,16 +157,17 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".github/workflows/macos.yml"
|
161
|
+
- ".github/workflows/ubuntu.yml"
|
162
|
+
- ".github/workflows/windows.yml"
|
160
163
|
- ".gitignore"
|
161
164
|
- ".rspec"
|
162
165
|
- ".rubocop.yml"
|
163
|
-
- ".travis.yml"
|
164
166
|
- Gemfile
|
165
167
|
- Gemfile.lock
|
166
168
|
- LICENSE.txt
|
167
169
|
- README.adoc
|
168
170
|
- Rakefile
|
169
|
-
- appveyor.yml
|
170
171
|
- bin/console
|
171
172
|
- bin/setup
|
172
173
|
- docs/hash.adoc
|
@@ -221,8 +222,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
221
222
|
- !ruby/object:Gem::Version
|
222
223
|
version: '0'
|
223
224
|
requirements: []
|
224
|
-
|
225
|
-
rubygems_version: 2.6.12
|
225
|
+
rubygems_version: 3.0.6
|
226
226
|
signing_key:
|
227
227
|
specification_version: 4
|
228
228
|
summary: 'RelatonBib: Ruby XMLDOC impementation.'
|
data/.travis.yml
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
# Auto-generated !!! Do not edit it manually
|
2
|
-
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
-
language: ruby
|
4
|
-
cache: bundler
|
5
|
-
os:
|
6
|
-
- linux
|
7
|
-
- osx
|
8
|
-
rvm:
|
9
|
-
- 2.6
|
10
|
-
- 2.5
|
11
|
-
- 2.4
|
12
|
-
- ruby-head
|
13
|
-
before_install:
|
14
|
-
- gem install bundler -v "~> 2"
|
15
|
-
- bundle update
|
16
|
-
matrix:
|
17
|
-
allow_failures:
|
18
|
-
- rvm: ruby-head
|
data/appveyor.yml
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
# Auto-generated !!! Do not edit it manually
|
2
|
-
# use ci-master https://github.com/metanorma/metanorma-build-scripts
|
3
|
-
version: '{build}'
|
4
|
-
|
5
|
-
cache:
|
6
|
-
- vendor/bundle
|
7
|
-
|
8
|
-
environment:
|
9
|
-
matrix:
|
10
|
-
- RUBY_VERSION: 26
|
11
|
-
- RUBY_VERSION: 25
|
12
|
-
- RUBY_VERSION: 24
|
13
|
-
- RUBY_VERSION: _trunk
|
14
|
-
|
15
|
-
matrix:
|
16
|
-
allow_failures:
|
17
|
-
- RUBY_VERSION: _trunk
|
18
|
-
|
19
|
-
install:
|
20
|
-
- ps: . { iwr -useb https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/appveyor.ps1 } | iex
|
21
|
-
- refreshenv
|
22
|
-
|
23
|
-
build_script:
|
24
|
-
- set PATH=C:\Ruby%RUBY_VERSION%\bin;%PATH%
|
25
|
-
- set GIT_TERMINAL_PROMPT=0
|
26
|
-
- gem install bundler -v "~> 2"
|
27
|
-
- bundle config --local path vendor/bundle
|
28
|
-
- bundle update
|
29
|
-
- bundle install
|
30
|
-
|
31
|
-
before_test:
|
32
|
-
- ruby -v
|
33
|
-
- gem -v
|
34
|
-
- bundle -v
|
35
|
-
|
36
|
-
test_script:
|
37
|
-
- bundle exec rake
|