relaton-cli 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 46e2d1bdc96570253e252c25e3a19758cea3bc3351152760b5698a37ab6a1959
4
- data.tar.gz: 91c22fe6506bce215c37e0aca6b61554fc6b39b857ddda812ece6031b5bfe89d
3
+ metadata.gz: 7fdcb1820641391e7cddeb35b48d11d0fe0cdbb76712e3295c16bcbb60b3634b
4
+ data.tar.gz: cad8f85257a2eb9eb59035bd2a7b4515a3d9b0332803c430f90a25cbc85c9554
5
5
  SHA512:
6
- metadata.gz: 5a90240c3672fed05369cf0c166d666eb012d3adddb9bbf39b04f2ee2d1e3c603f652144324d9aeec0c69fb1f32c564ebe414b34a1b56d9688fd07e72e18e608
7
- data.tar.gz: c72e91f93f788e8cb0aae092e03412f6d3510c8647bab62fb4b40d6c1403eb8e1a8127d019587a5b5cfa87701b9d7157d86f0feef91a627cf67b4ccbd58f5d23
6
+ metadata.gz: 31090e660806cca71e117e4122ed364d86c576fb40feb63eb747385502e2fe4d4a3c128bb148efcf351e6070e7beb8c9947cb586aad3eb28cbaeebbe0c4f91af
7
+ data.tar.gz: 4114acb8fd5e55c822d192ac181155914e5f4eadb87c73b0f3873a3279aa51c7818d5ed79b551121c6ad75753373b44a2ee5f6f150f272ea2d0909671231e2de
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: macos
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-macos:
9
13
  name: Test on Ruby ${{ matrix.ruby }} macOS
10
14
  runs-on: macos-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -20,7 +25,7 @@ jobs:
20
25
  architecture: 'x64'
21
26
  - name: Update gems
22
27
  run: |
23
- sudo gem install bundler -v "~> 2" --force
28
+ sudo gem install bundler --force
24
29
  bundle install --jobs 4 --retry 3
25
30
  - name: Run specs
26
31
  run: |
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: ubuntu
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-linux:
9
13
  name: Test on Ruby ${{ matrix.ruby }} Ubuntu
10
14
  runs-on: ubuntu-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -20,7 +25,7 @@ jobs:
20
25
  architecture: 'x64'
21
26
  - name: Update gems
22
27
  run: |
23
- gem install bundler -v "~> 2"
28
+ gem install bundler
24
29
  bundle install --jobs 4 --retry 3
25
30
  - name: Run specs
26
31
  run: |
@@ -1,14 +1,19 @@
1
- # Auto-generated !!! Do not edit it manually
2
- # use ci-master https://github.com/metanorma/metanorma-build-scripts
1
+ # Auto-generated by Cimas: Do not edit it manually!
2
+ # See https://github.com/metanorma/cimas
3
3
  name: windows
4
4
 
5
- on: [push]
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+ branches: [ '**' ]
6
10
 
7
11
  jobs:
8
12
  test-windows:
9
13
  name: Test on Ruby ${{ matrix.ruby }} Windows
10
14
  runs-on: windows-latest
11
15
  strategy:
16
+ fail-fast: false
12
17
  matrix:
13
18
  ruby: [ '2.6', '2.5', '2.4' ]
14
19
  steps:
@@ -21,7 +26,7 @@ jobs:
21
26
  - name: Update gems
22
27
  shell: pwsh
23
28
  run: |
24
- gem install bundler -v "~> 2"
29
+ gem install bundler
25
30
  bundle config --local path vendor/bundle
26
31
  bundle update
27
32
  bundle install --jobs 4 --retry 3
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/docs/README.adoc CHANGED
@@ -18,7 +18,7 @@ The following commands are provided.
18
18
 
19
19
  [source,console]
20
20
  ----
21
- $ relaton concatenate Source-Directory Relaton-Collection-File -t TITLE -g ORGANIZATION -n
21
+ $ relaton concatenate Source-Directory Relaton-Collection-File -t TITLE -g ORGANIZATION
22
22
  ----
23
23
 
24
24
  Iterates through all the Relaton files (YAML and XML) in `Source-Directory`, and concatenates them into a Relaton Collection file. The extension of the Collection file can be set using the `Relaton-Collection-File` file name (i.e, if it uses an extension of `yaml`, a Relaton YAML file will be created; if `rxl`, a Relaton XML file will be created, or via the `-x [ext]` (or `--extension`) option.
@@ -29,20 +29,16 @@ file), a link to that file is inserted.
29
29
  If the `TITLE` or `ORGANIZATION` options are given, they are added to the `Collection-File` output as the
30
30
  title and author of the `Relaton-Collection-File` document.
31
31
 
32
- If the `-n` or `--new` option given then use the new Relaton YAML format https://github.com/relaton/relaton-bib/blob/master/docs/hash.adoc.
33
-
34
32
  === relaton split
35
33
 
36
34
  [source,console]
37
35
  ----
38
- $ relaton split Relaton-Collection-File Relaton-File-Directory -x rxl -n
36
+ $ relaton split Relaton-Collection-File Relaton-File-Directory -x rxl
39
37
  ----
40
38
 
41
39
  Splits a `Relaton-Collection-File` into multiple files in the `Relaton-File-Directory`, and it also
42
40
  suports an additional `-x` or `--extension` options to use different extension.
43
41
 
44
- If the `-n` or `--new` option given then use the new Relaton YAML format https://github.com/relaton/relaton-bib/blob/master/docs/hash.adoc.
45
-
46
42
  === relaton fetch
47
43
 
48
44
  [source,console]
@@ -146,7 +142,6 @@ Sample HTML output for a bibliographic entry:
146
142
  </div>
147
143
  ----
148
144
 
149
- [[relaton-yaml]]
150
145
  === relaton yaml2xml
151
146
 
152
147
  [source,console]
@@ -156,67 +151,7 @@ $ relaton yaml2xml YAML -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LI
156
151
 
157
152
  Convert a Relaton YAML file (`filename.yaml`) into a Relaton XML file (`filename.xml`). If the Relaton YAML file specifies multiple bibliograph items, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton XML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.rxl`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
158
153
 
159
- A Relaton Colleciton YAML file contains some initial metadata, and a list of metadata about each bibliographic entry. A Relaton YAML file describing an individual bibliographic entry is limited to metadata specific to that entry. The following illustrates the fields supported:
160
-
161
- [source,yaml]
162
- ----
163
- htmlstylesheet: ./index-style.css
164
- root:
165
- title: CalConnect Standards Registry
166
- author: "CalConnect: The Calendaring and Scheduling Consortium"
167
- items:
168
- - technical_committee: TC VCARD
169
- docidentifier: 18001
170
- doctype: standard
171
- title: "Date and time -- Representations for information interchange -- Part 1: Basic rules"
172
- stage: Published
173
- revdate: 2018-10-17
174
- xml: standards/csd-datetime-explict/csd-datetime-explict.xml
175
- html: standards/csd-datetime-explict/csd-datetime-explict.html
176
- pdf: standards/csd-datetime-explict/csd-datetime-explict.pdf
177
- doc: standards/csd-datetime-explict/csd-datetime-explict.doc
178
- relaton: standards/csd-datetime-explict/cc-18001.xml
179
- - technical_committee: TC PUBLISH
180
- docidentifier: 10001
181
- doctype: governance
182
- title: "Standardization and publication"
183
- stage: proposal
184
- revdate: 2018-10-17
185
- uri: standards/csd-standardization/csd-standardization.xml
186
- agency: CalConnect
187
- language: en
188
- script: Latn
189
- edition: 1
190
- ----
191
-
192
- === relaton xml2yaml
193
-
194
- [source,console]
195
- ----
196
- $ relaton xml2yaml XML -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
197
- ----
198
-
199
- Convert a Relaton XML file (`filename.xml` or `filename.rxl`) into a Relaton YAML file (`filename.yaml`). If the Relaton XML file is a collection, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton YAML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.yaml`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
200
-
201
-
202
- === relaton yaml2html
203
-
204
- [source,console]
205
- ----
206
- $ relaton yaml2xml <filename.yaml> [<stylesheet>] [<liquid-template-dir>]
207
- ----
208
-
209
- Render a Relaton YAML file (`filename.yaml`) as an HTML file. The stylesheet and liquid-template-dir directories are as for <<relaton-xml2html,relaton xml2html>>.
210
-
211
- === relaton yaml2xmlnew
212
-
213
- [source,console]
214
- ----
215
- $ relaton yaml2xmlnew <filename.yaml> -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
216
- ----
217
-
218
- Convert a Relaton YAML file (`filename.yaml`) in a new format into a Relaton XML file (`filename.xml`). If the Relaton YAML file specifies multiple bibliographic items, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton XML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.rxl`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
219
-
154
+ [[relaton-yaml]]
220
155
  A Relaton Collection YAML file contains some initial metadata, and a list of metadata about each bibliographic entry:
221
156
 
222
157
  [source,yaml]
@@ -253,220 +188,23 @@ root:
253
188
  value: 2018-10-25
254
189
  ----
255
190
 
256
- A Relaton YAML file describing an individual bibliographic entry is limited to metadata specific to that entry. Flavor gems have additional fields. The following illustrates the common fields supported by all flavor gems (see link:https://github.com/relaton/relaton-bib/blob/master/docs/hash.adoc#yaml[Relaton YAML]):
257
-
258
- [source,yaml]
259
- ----
260
- ---
261
- id: ISO/TC211
262
- title:
263
- - type: main
264
- content: Geographic information
265
- language: en
266
- script: Latn
267
- format: text/plain
268
- - content: Information géographique
269
- language: fr
270
- script: Latn
271
- format: text/plain
272
- link:
273
- - type: src
274
- content: https://www.iso.org/standard/53798.html
275
- - type: obp
276
- content: https://www.iso.org/obp/ui/#!iso:std:53798:en
277
- - type: rss
278
- content: https://www.iso.org/contents/data/standard/05/37/53798.detail.rss
279
- type: standard
280
- docid:
281
- id: TC211
282
- type: ISO
283
- docnumber: '123456'
284
- date:
285
- - type: issued
286
- value: '2014-01-01'
287
- - type: published
288
- value: '2014-04-01'
289
- - type: accessed
290
- value: '2015-05-20'
291
- contributor:
292
- - organization:
293
- name: International Organization for Standardization
294
- abbreviation: ISO
295
- subdivision: division
296
- url: www.iso.org
297
- role:
298
- description: Publisher role
299
- type: publisher
300
- - person:
301
- name:
302
- completename:
303
- content: A. Bierman
304
- language: en
305
- affiliation:
306
- organization:
307
- name: IETF
308
- abbreviation: IETF
309
- identifier:
310
- type: uri
311
- id: www.ietf.org
312
- contact:
313
- - street:
314
- - Street
315
- city: City
316
- state: State
317
- country: Country
318
- postcode: '123456'
319
- - type: phone
320
- value: '223322'
321
- role: author
322
- - organization:
323
- name: IETF
324
- abbreviation: IETF
325
- identifier:
326
- type: uri
327
- id: www.ietf.org
328
- role: publisher
329
- - person:
330
- name:
331
- forename:
332
- content: Forename
333
- language: en
334
- initial:
335
- content: A.
336
- language: en
337
- surname:
338
- content: Bierman
339
- language: en
340
- addition:
341
- content: Addition
342
- language: en
343
- prefix:
344
- content: Prefix
345
- language: en
346
- affiliation:
347
- organization:
348
- name: IETF
349
- abbreviation: IETF
350
- description:
351
- content: Description
352
- language: en
353
- identifier:
354
- type: uri
355
- id: www.person.com
356
- contact:
357
- - street:
358
- - Street
359
- city: City
360
- state: State
361
- country: Country
362
- postcode: '123456'
363
- - type: phone
364
- value: '223322'
365
- role: author
366
- edition: '1'
367
- version:
368
- revision_date: '2019-04-01'
369
- draft: draft
370
- biblionote:
371
- content: note
372
- type: bibnote
373
- language:
374
- - en
375
- - fr
376
- script: Latn
377
- abstract:
378
- - content: ISO 19115-1:2014 defines the schema required for ...
379
- language: en
380
- script: Latn
381
- format: text/plain
382
- - content: L'ISO 19115-1:2014 définit le schéma requis pour ...
383
- language: fr
384
- script: Latn
385
- format: text/plain
386
- docstatus:
387
- stage: stage
388
- substage: substage
389
- iteration: final
390
- copyright:
391
- owner:
392
- name: International Organization for Standardization
393
- abbreviation: ISO
394
- url: www.iso.org
395
- from: '2014'
396
- to: '2020'
397
- relation:
398
- - type: updates
399
- bibitem:
400
- formattedref:
401
- content: ISO 19115:2003
402
- format: text/plain
403
- bib_locality:
404
- type: updates
405
- reference_from: Reference form
406
- - type: updates
407
- bibitem:
408
- type: standard
409
- formattedref:
410
- content: ISO 19115:2003/Cor 1:2006
411
- format: text/plain
412
- series:
413
- - type: main
414
- title:
415
- type: original
416
- content: ISO/IEC FDIS 10118-3
417
- language: en
418
- script: Latn
419
- format: text/plain
420
- place: Serie's place
421
- organization: Serie's organization
422
- abbreviation: ABVR
423
- from: '2009-02-01'
424
- to: '2010-12-20'
425
- number: serie1234
426
- partnumber: part5678
427
- - type: alt
428
- formattedref:
429
- content: serieref
430
- language: en
431
- script: Latn
432
- format: text/plain
433
- medium:
434
- form: medium form
435
- size: medium size
436
- scale: medium scale
437
- place: bib place
438
- extent:
439
- type: section
440
- reference_from: Reference from
441
- reference_to: Reference to
442
- accesslocation:
443
- - accesslocation1
444
- - accesslocation2
445
- classification:
446
- value: value
447
- type: type
448
- validity:
449
- begins: 2010-10-10 12:21
450
- ends: 2011-02-03 18:30
451
- revision: 2011-03-04 09:00
452
- fetched: '2019-08-16'
453
- ----
191
+ A Relaton YAML file describing an individual bibliographic entry is limited to metadata specific to that entry. Flavor gems have additional fields. The link:https://github.com/relaton/relaton-bib/blob/master/docs/hash.adoc#yaml[Relaton YAML] illustrates the common fields supported by all flavor gems.
454
192
 
455
- === relaton xml2yamlnew
193
+ === relaton xml2yaml
456
194
 
457
195
  [source,console]
458
196
  ----
459
- $ relaton xml2yamlnew <filename.xml> -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
197
+ $ relaton xml2yaml XML -o OUTPUT-DIRECTORY -x RELATON_EXTENSION -p PREFIX -r LIBRARY
460
198
  ----
461
199
 
462
- Convert a Relaton XML file (`filename.xml` or `filename.rxl`) into a Relaton YAML file (`filename.yaml`) in a new format. If the Relaton XML file is a collection, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton YAML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.yaml`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
200
+ Convert a Relaton XML file (`filename.xml` or `filename.rxl`) into a Relaton YAML file (`filename.yaml`). If the Relaton XML file is a collection, and `OUTPUT-DIRECTORY` is nominated, also convert the file into a list of Relaton YAML files for each entry, stored in that directory. The document identifier is used as the name of each Relaton XML file; the Relaton XML filename is suffixed with `RELATON_EXTENSION` (default `.yaml`) and prefixed with `PREFIX` (default empty). Any libraries that need to be required for the conversion are specified in `LIBRARY` as a space-delimited list.
463
201
 
464
- === relaton yaml2htmlnew
202
+ === relaton yaml2html
465
203
 
466
204
  [source,console]
467
205
  ----
468
- $ relaton yaml2xmlnew <filename.yaml> [<stylesheet>] [<liquid-template-dir>]
206
+ $ relaton yaml2html YAML [<stylesheet>] [<liquid-template-dir>]
469
207
  ----
470
208
 
471
- Render a Relaton YAML file in a new format (`filename.yaml`) as an HTML file. The `stylesheet` and `liquid-template-dir` directories are as for <<relaton xml2html,relaton xml2html>>.
209
+ Render a Relaton YAML file (`filename.yaml`) as an HTML file. The `stylesheet` and `liquid-template-dir` directories are as for <<relaton-xml2html,relaton xml2html>>.
472
210
 
@@ -9,7 +9,7 @@ module Relaton
9
9
  items
10
10
  doctype
11
11
  author
12
- ]
12
+ ].freeze
13
13
 
14
14
  attr_accessor *ATTRIBS
15
15
 
@@ -17,16 +17,14 @@ module Relaton
17
17
  self.items = []
18
18
  ATTRIBS.each do |k|
19
19
  value = options[k] || options[k.to_s]
20
- self.send("#{k}=", value)
20
+ send("#{k}=", value)
21
21
  end
22
- self.items = (self.items || []).inject([]) do |acc, item|
22
+ self.items = (items || []).reduce([]) do |acc, item|
23
23
  acc << if item.is_a?(::Relaton::Bibcollection) || item.is_a?(::Relaton::Bibdata)
24
- item
25
- else
26
- new_bib_item_class(item)
27
- end
24
+ item
25
+ else new_bib_item_class(item)
26
+ end
28
27
  end
29
- self
30
28
  end
31
29
 
32
30
  # arbitrary number, must sort after all bib items
@@ -39,7 +37,7 @@ module Relaton
39
37
  author = find_text("./relaton-collection/contributor[role/@type = 'author']/organization/name", source)
40
38
 
41
39
  items = find_xpath("./relaton-collection/relation", source)&.map do |item|
42
- bibdata = find("./bibdata | ./bibitem", item)
40
+ bibdata = find("./bibdata", item)
43
41
  klass = bibdata ? Bibdata : Bibcollection
44
42
  klass.from_xml(bibdata || item)
45
43
  end
@@ -48,16 +46,16 @@ module Relaton
48
46
  end
49
47
 
50
48
  def new_bib_item_class(options)
51
- if options["items"]
52
- options[:new] ? ::Relaton::BibcollectionNew(options) : ::Relaton::Bibcollection.new(options)
49
+ if options.is_a?(Hash) && options["items"]
50
+ ::Relaton::Bibcollection.new(options)
53
51
  else
54
- options[:new] ? ::Relaton::BibdataNew(options) : ::Relaton::Bibdata.new(options)
52
+ ::Relaton::Bibdata.new(options)
55
53
  end
56
54
  end
57
55
 
58
56
  def items_flattened
59
57
  items.sort_by! do |b|
60
- b.doc_number
58
+ b.docnumber
61
59
  end
62
60
 
63
61
  items.inject([]) do |acc,item|
@@ -2,46 +2,34 @@ require "date"
2
2
 
3
3
  module Relaton
4
4
  class Bibdata
5
- ATTRIBS = %i[
6
- docidentifier
7
- doctype
8
- title
9
- stage
10
- relation
11
- xml
12
- pdf
13
- doc
14
- html
15
- uri
16
- rxl
17
- txt
18
- revdate
19
- abstract
20
- technical_committee
21
- copyright_from
22
- copyright_owner
23
- contributor_author_role
24
- contributor_author_organization
25
- contributor_author_person
26
- contributor_publisher_role
27
- contributor_publisher_organization
28
- language
29
- script
30
- edition
31
- datetype
32
- bib_rxl
33
- ref
34
- ]
35
-
36
- attr_accessor *ATTRIBS
37
-
38
- def initialize(options)
39
- options.each_pair do |k,v|
40
- send("#{k.to_s}=", v)
41
- end
42
- self
5
+ URL_TYPES = %i[uri xml pdf doc html rxl txt]
6
+
7
+ attr_reader :bibitem
8
+
9
+ def initialize(bibitem)
10
+ @bibitem = bibitem
11
+ end
12
+
13
+ # def method_missing(method, *args)
14
+ # %r{(?<m>\w+)=$} =~ method
15
+ # return unless m && %w[xml pdf doc html rxl txt].include?(m)
16
+
17
+ # uri = @bibitem.link.detect { |u| u.type == m }
18
+ # if uri
19
+ # uri.content = args[0]
20
+ # else
21
+ # @bibitem.link << RelatonBib::TypedUri.new(type: m, content: args[0])
22
+ # end
23
+ # end
24
+
25
+ def docidentifier
26
+ @bibitem.docidentifier.first&.id
43
27
  end
44
28
 
29
+ # def doctype
30
+ # @bibitem.type
31
+ # end
32
+
45
33
  # From http://gavinmiller.io/2016/creating-a-secure-sanitization-function/
46
34
  FILENAME_BAD_CHARS = [ '/', '\\', '?', '%', '*', ':', '|', '"', '<', '>', '.', ' ' ]
47
35
 
@@ -58,78 +46,48 @@ module Relaton
58
46
  end
59
47
 
60
48
  def self.from_xml(source)
61
- new(Relaton::XmlDocument.parse(source))
49
+ new(Relaton::Cli.parse_xml(source))
62
50
  end
63
51
 
64
52
  def to_xml(opts = {})
65
- #datetype = stage&.casecmp("published") == 0 ? "published" : "circulated"
66
-
67
- ret = ref ? "<bibitem id= '#{ref}' type='#{doctype}'>\n" : "<bibdata type='#{doctype}'>\n"
68
- ret += "<fetched>#{Date.today.to_s}</fetched>\n"
69
- ret += "<title>#{title}</title>\n"
70
- ret += "<docidentifier>#{docidentifier}</docidentifier>\n" if docidentifier
71
- ret += "<uri>#{uri}</uri>\n" if uri
72
- ret += "<uri type='xml'>#{xml}</uri>\n" if xml
73
- ret += "<uri type='html'>#{html}</uri>\n" if html
74
- ret += "<uri type='pdf'>#{pdf}</uri>\n" if pdf
75
- ret += "<uri type='doc'>#{doc}</uri>\n" if doc
76
- ret += "<uri type='rxl'>#{rxl}</uri>\n" if rxl
77
-
78
- ret += "<language>#{language}</language>\n"
79
- ret += "<script>#{script}</script>\n"
80
-
81
- if copyright_from
82
- ret += "<copyright>"
83
- ret += "<from>#{copyright_from}</from>\n" if copyright_from
84
- ret += "<owner><organization><name>#{copyright_owner}</name></organization></owner>\n" if copyright_owner
85
- ret += "</copyright>"
86
- end
53
+ options = { bibdata: true, date_format: :full }.merge opts.select { |k,v| k.is_a? Symbol }
54
+ @bibitem.to_xml nil, **options
87
55
 
88
- if contributor_author_role
89
- ret += "<contributor>\n"
90
- ret += "<role type='author'/>\n"
91
- ret += "<organization><name>#{contributor_author_organization}</name></organization>\n"
92
- ret += "</contributor>\n"
93
- end
56
+ # #datetype = stage&.casecmp("published") == 0 ? "published" : "circulated"
94
57
 
95
- if contributor_author_person
96
- Array(contributor_author_person).each do |name|
97
- ret += "<contributor>\n"
98
- ret += "<role type='author'/>\n"
99
- ret += "<person><name><completename>#{name}</completename></name></person>\n"
100
- ret += "</contributor>\n"
101
- end
102
- end
103
-
104
- if contributor_publisher_role
105
- ret += "<contributor>\n"
106
- ret += "<role type='publisher'/>\n"
107
- ret += "<organization><name>#{contributor_publisher_organization}</name></organization>\n"
108
- ret += "</contributor>\n"
109
- end
110
-
111
- ret += "<date type='#{datetype}'><on>#{revdate}</on></date>\n" if revdate
112
- # ret += "<contributor><role type='author'/><organization><name>#{agency}</name></organization></contributor>" if agency
113
- # ret += "<contributor><role type='publisher'/><organization><name>#{agency}</name></organization></contributor>" if agency
114
- ret += "<edition>#{edition}</edition>\n" if edition
115
- ret += "<language>#{language}</language>\n" if language
116
- ret += "<script>#{script}</script>\n" if script
117
- ret += "<abstract>#{abstract}</abstract>\n" if abstract
118
- ret += "<status>#{stage}</status>\n" if stage
119
- ret += "<editorialgroup><technical-committee>#{technical_committee}</technical-committee></editorialgroup>\n" if technical_committee
120
- ret += ref ? "</bibitem>\n" : "</bibdata>\n"
58
+ # ret = ref ? "<bibitem id= '#{ref}' type='#{doctype}'>\n" : "<bibdata type='#{doctype}'>\n"
59
+ # ret += "<fetched>#{Date.today.to_s}</fetched>\n"
121
60
  end
122
61
 
123
62
  def to_h
124
- ATTRIBS.inject({}) do |acc, k|
125
- value = send(k)
126
- acc[k.to_s] = value unless value.nil?
127
- acc
63
+ URL_TYPES.reduce(@bibitem.to_hash) do |h, t|
64
+ value = self.send t
65
+ h[t.to_s] = value
66
+ h
128
67
  end
129
68
  end
130
69
 
131
70
  def to_yaml
132
71
  to_h.to_yaml
133
72
  end
73
+
74
+ def method_missing(meth, *args)
75
+ if @bibitem.respond_to?(meth)
76
+ @bibitem.send meth, *args
77
+ elsif URL_TYPES.include? meth
78
+ link = @bibitem.link.detect { |l| l.type == meth.to_s || meth == :uri && l.type.nil? }
79
+ link&.content&.to_s
80
+ elsif URL_TYPES.include? meth.match(/^\w+(?==)/).to_s.to_sym
81
+ /^(?<type>\w+)/ =~ meth
82
+ link = @bibitem.link.detect { |l| l.type == type || type == "uri" && l.type.nil? }
83
+ if link
84
+ link.content = args[0]
85
+ else
86
+ @bibitem.link << RelatonBib::TypedUri.new(type: type, content: args[0])
87
+ end
88
+ else
89
+ super
90
+ end
91
+ end
134
92
  end
135
93
  end