relaton-cli 0.3.6 → 0.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -15
- data/docs/README.adoc +6 -2
- data/lib/relaton-cli.rb +0 -1
- data/lib/relaton/bibcollection.rb +4 -5
- data/lib/relaton/bibcollectionnew.rb +4 -5
- data/lib/relaton/bibdatanew.rb +62 -0
- data/lib/relaton/cli.rb +19 -0
- data/lib/relaton/cli/base_convertor.rb +3 -2
- data/lib/relaton/cli/command.rb +2 -0
- data/lib/relaton/cli/relaton_file.rb +26 -8
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_convertor_new.rb +2 -21
- data/lib/relaton/cli/yaml_convertor_new.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 29ee3d1187d6023ead4d9f5cc04bd4bddb7e2931
|
|
4
|
+
data.tar.gz: bef6cd7d3d4c586f5843386bf2d1ca146cdd013f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78fa395ed259c408f7368170a53459229a6c21efae0f392362eefdb44b9c44a93fa740845bdd7bb87c2787d0bbfbf2500fcc607c7501a2b5f9e61b493ba390a2
|
|
7
|
+
data.tar.gz: 2594375e739b8d943d16d40079d776807a2bf622bdb46edec7dccabf9f3bf2d699574fec19a5314ef2cc80a0fece75c752d25faf0d148fe9d8626a8a0700ed5b
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
relaton-cli (0.3.
|
|
4
|
+
relaton-cli (0.3.7)
|
|
5
5
|
liquid
|
|
6
6
|
relaton (~> 0.5)
|
|
7
7
|
thor
|
|
@@ -12,7 +12,7 @@ GEM
|
|
|
12
12
|
addressable (2.7.0)
|
|
13
13
|
public_suffix (>= 2.0.2, < 5.0)
|
|
14
14
|
byebug (10.0.2)
|
|
15
|
-
cnccs (0.1.
|
|
15
|
+
cnccs (0.1.4)
|
|
16
16
|
coderay (1.1.2)
|
|
17
17
|
debase (0.2.3)
|
|
18
18
|
debase-ruby_core_source (>= 0.10.2)
|
|
@@ -21,10 +21,10 @@ GEM
|
|
|
21
21
|
docile (1.3.2)
|
|
22
22
|
equivalent-xml (0.6.0)
|
|
23
23
|
nokogiri (>= 1.4.3)
|
|
24
|
-
faraday (0.
|
|
24
|
+
faraday (0.17.0)
|
|
25
25
|
multipart-post (>= 1.2, < 3)
|
|
26
|
-
gb-agencies (0.0.
|
|
27
|
-
isoics (0.1.
|
|
26
|
+
gb-agencies (0.0.6)
|
|
27
|
+
isoics (0.1.8)
|
|
28
28
|
json (2.2.0)
|
|
29
29
|
liquid (4.0.3)
|
|
30
30
|
method_source (0.9.2)
|
|
@@ -38,7 +38,7 @@ GEM
|
|
|
38
38
|
method_source (~> 0.9.0)
|
|
39
39
|
public_suffix (4.0.1)
|
|
40
40
|
rake (12.3.3)
|
|
41
|
-
relaton (0.5.
|
|
41
|
+
relaton (0.5.6)
|
|
42
42
|
relaton-gb (~> 0.6.0)
|
|
43
43
|
relaton-iec (~> 0.4.0)
|
|
44
44
|
relaton-ietf (~> 0.6.0)
|
|
@@ -46,31 +46,31 @@ GEM
|
|
|
46
46
|
relaton-itu (~> 0.3.0)
|
|
47
47
|
relaton-nist (~> 0.3.0)
|
|
48
48
|
relaton-ogc (~> 0.1.0)
|
|
49
|
-
relaton-bib (0.3.
|
|
49
|
+
relaton-bib (0.3.9)
|
|
50
50
|
addressable
|
|
51
51
|
nokogiri
|
|
52
|
-
relaton-gb (0.6.
|
|
52
|
+
relaton-gb (0.6.5)
|
|
53
53
|
cnccs (~> 0.1.1)
|
|
54
54
|
gb-agencies (~> 0.0.1)
|
|
55
55
|
relaton-iso-bib (~> 0.3.0)
|
|
56
|
-
relaton-iec (0.4.
|
|
56
|
+
relaton-iec (0.4.8)
|
|
57
57
|
addressable
|
|
58
58
|
relaton-iso-bib (~> 0.3.0)
|
|
59
|
-
relaton-ietf (0.6.
|
|
59
|
+
relaton-ietf (0.6.6)
|
|
60
60
|
relaton-bib (~> 0.3.0)
|
|
61
|
-
relaton-iso (0.6.
|
|
61
|
+
relaton-iso (0.6.7)
|
|
62
62
|
relaton-iec (~> 0.4.0)
|
|
63
63
|
relaton-iso-bib (~> 0.3.0)
|
|
64
|
-
relaton-iso-bib (0.3.
|
|
64
|
+
relaton-iso-bib (0.3.9)
|
|
65
65
|
isoics (~> 0.1.6)
|
|
66
66
|
relaton-bib (~> 0.3.0)
|
|
67
67
|
ruby_deep_clone (~> 0.8.0)
|
|
68
|
-
relaton-itu (0.3.
|
|
68
|
+
relaton-itu (0.3.5)
|
|
69
69
|
relaton-iso-bib (~> 0.3.0)
|
|
70
|
-
relaton-nist (0.3.
|
|
70
|
+
relaton-nist (0.3.6)
|
|
71
71
|
relaton-bib (~> 0.3.0)
|
|
72
72
|
rubyzip
|
|
73
|
-
relaton-ogc (0.1.
|
|
73
|
+
relaton-ogc (0.1.2)
|
|
74
74
|
faraday
|
|
75
75
|
relaton-iso-bib (~> 0.3.0)
|
|
76
76
|
rspec (3.8.0)
|
data/docs/README.adoc
CHANGED
|
@@ -17,7 +17,7 @@ The following executables are included:
|
|
|
17
17
|
|
|
18
18
|
[source,console]
|
|
19
19
|
----
|
|
20
|
-
$ relaton concatenate Source-Directory Collection-File -t TITLE -g ORGANIZATION
|
|
20
|
+
$ relaton concatenate Source-Directory Collection-File -t TITLE -g ORGANIZATION -n
|
|
21
21
|
----
|
|
22
22
|
|
|
23
23
|
Iterates through all the Relaton YAML files in `Source-Directory`, and converts them in-place into Relaton XML.
|
|
@@ -31,16 +31,20 @@ file), a link to that file is inserted.
|
|
|
31
31
|
If the `TITLE` or `ORGANIZATION` options are given, they are added to the `Collection-File` output as the
|
|
32
32
|
title and author of the `relaton-collection` document.
|
|
33
33
|
|
|
34
|
+
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.
|
|
35
|
+
|
|
34
36
|
=== relaton split
|
|
35
37
|
|
|
36
38
|
[source,console]
|
|
37
39
|
----
|
|
38
|
-
$ relaton split Collection-File Relaton-File-Directory -x rxl
|
|
40
|
+
$ relaton split Collection-File Relaton-File-Directory -x rxl -n
|
|
39
41
|
----
|
|
40
42
|
|
|
41
43
|
Splits a `Relaton-Collection-File` into multiple files in the `Relaton-File-Directory`, and it also
|
|
42
44
|
suports an addional `extension` options to use different extension.
|
|
43
45
|
|
|
46
|
+
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.
|
|
47
|
+
|
|
44
48
|
=== relaton fetch
|
|
45
49
|
|
|
46
50
|
[source,console]
|
data/lib/relaton-cli.rb
CHANGED
|
@@ -19,9 +19,8 @@ module Relaton
|
|
|
19
19
|
value = options[k] || options[k.to_s]
|
|
20
20
|
self.send("#{k}=", value)
|
|
21
21
|
end
|
|
22
|
-
self.items = (self.items || []).inject([]) do |acc,item|
|
|
23
|
-
acc << if item.is_a?(::Relaton::Bibcollection) ||
|
|
24
|
-
item.is_a?(::Relaton::Bibdata)
|
|
22
|
+
self.items = (self.items || []).inject([]) do |acc, item|
|
|
23
|
+
acc << if item.is_a?(::Relaton::Bibcollection) || item.is_a?(::Relaton::Bibdata)
|
|
25
24
|
item
|
|
26
25
|
else
|
|
27
26
|
new_bib_item_class(item)
|
|
@@ -50,9 +49,9 @@ module Relaton
|
|
|
50
49
|
|
|
51
50
|
def new_bib_item_class(options)
|
|
52
51
|
if options["items"]
|
|
53
|
-
::Relaton::Bibcollection.new(options)
|
|
52
|
+
options[:new] ? ::Relaton::BibcollectionNew(options) : ::Relaton::Bibcollection.new(options)
|
|
54
53
|
else
|
|
55
|
-
::Relaton::Bibdata.new(options)
|
|
54
|
+
options[:new] ? ::Relaton::BibdataNew(options) : ::Relaton::Bibdata.new(options)
|
|
56
55
|
end
|
|
57
56
|
end
|
|
58
57
|
|
|
@@ -20,8 +20,7 @@ module Relaton
|
|
|
20
20
|
send("#{k}=", value)
|
|
21
21
|
end
|
|
22
22
|
self.items = (items || []).reduce([]) do |acc, item|
|
|
23
|
-
acc << if item.is_a?(::Relaton::BibcollectionNew) ||
|
|
24
|
-
item.class >= ::RelatonBib::BibliographicItem
|
|
23
|
+
acc << if item.is_a?(::Relaton::BibcollectionNew) || item.is_a?(::Relaton::BibdataNew)
|
|
25
24
|
item
|
|
26
25
|
else new_bib_item_class(item)
|
|
27
26
|
end
|
|
@@ -39,7 +38,7 @@ module Relaton
|
|
|
39
38
|
|
|
40
39
|
items = find_xpath("./relaton-collection/relation", source)&.map do |item|
|
|
41
40
|
bibdata = find("./bibdata", item)
|
|
42
|
-
klass = bibdata ?
|
|
41
|
+
klass = bibdata ? BibdataNew : BibcollectionNew
|
|
43
42
|
klass.from_xml(bibdata || item)
|
|
44
43
|
end
|
|
45
44
|
|
|
@@ -47,10 +46,10 @@ module Relaton
|
|
|
47
46
|
end
|
|
48
47
|
|
|
49
48
|
def new_bib_item_class(options)
|
|
50
|
-
if options["items"]
|
|
49
|
+
if options.is_a?(Hash) && options["items"]
|
|
51
50
|
::Relaton::BibcollectionNew.new(options)
|
|
52
51
|
else
|
|
53
|
-
::
|
|
52
|
+
::Relaton::BibdataNew.new(options)
|
|
54
53
|
end
|
|
55
54
|
end
|
|
56
55
|
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "date"
|
|
2
|
+
|
|
3
|
+
module Relaton
|
|
4
|
+
class BibdataNew
|
|
5
|
+
def initialize(bibitem)
|
|
6
|
+
@bibitem = bibitem
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def method_missing(method, *args)
|
|
10
|
+
%r{(?<m>\w+)=$} =~ method
|
|
11
|
+
return unless m && %w[xml pdf doc html rxl txt].include?(m)
|
|
12
|
+
|
|
13
|
+
uri = @bibitem.link.detect { |u| u.type == method }
|
|
14
|
+
if uri
|
|
15
|
+
uri.content = args[0]
|
|
16
|
+
else
|
|
17
|
+
@bibitem.link << RelatonBib::TypedUri.new(type: m, content: args[0])
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def docidentifier
|
|
22
|
+
@bibitem.docidentifier.first&.id
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# From http://gavinmiller.io/2016/creating-a-secure-sanitization-function/
|
|
26
|
+
# FILENAME_BAD_CHARS = [ '/', '\\', '?', '%', '*', ':', '|', '"', '<', '>', '.', ' ' ]
|
|
27
|
+
|
|
28
|
+
# def docidentifier_code
|
|
29
|
+
# return "" if docidentifier.nil?
|
|
30
|
+
# a = FILENAME_BAD_CHARS.inject(docidentifier.downcase) do |result, bad_char|
|
|
31
|
+
# result.gsub(bad_char, '-')
|
|
32
|
+
# end
|
|
33
|
+
# end
|
|
34
|
+
|
|
35
|
+
# DOC_NUMBER_REGEX = /([\w\/]+)\s+(\d+):?(\d*)/
|
|
36
|
+
# def doc_number
|
|
37
|
+
# docidentifier&.match(DOC_NUMBER_REGEX) ? $2.to_i : 999999
|
|
38
|
+
# end
|
|
39
|
+
|
|
40
|
+
def self.from_xml(source)
|
|
41
|
+
new(Relaton::Cli.parse_xml(source))
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def to_xml(opts = {})
|
|
45
|
+
options = { bibdata: true, date_format: :full }.merge opts.select { |k,v| k.is_a? Symbol }
|
|
46
|
+
@bibitem.to_xml nil, **options
|
|
47
|
+
|
|
48
|
+
# #datetype = stage&.casecmp("published") == 0 ? "published" : "circulated"
|
|
49
|
+
|
|
50
|
+
# ret = ref ? "<bibitem id= '#{ref}' type='#{doctype}'>\n" : "<bibdata type='#{doctype}'>\n"
|
|
51
|
+
# ret += "<fetched>#{Date.today.to_s}</fetched>\n"
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def to_h
|
|
55
|
+
@bibitem.to_hash
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def to_yaml
|
|
59
|
+
to_h.to_yaml
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
data/lib/relaton/cli.rb
CHANGED
|
@@ -19,5 +19,24 @@ module Relaton
|
|
|
19
19
|
def self.relaton
|
|
20
20
|
@relaton ||= Relaton::Db.new("#{Dir.home}/.relaton/cache", nil)
|
|
21
21
|
end
|
|
22
|
+
|
|
23
|
+
# @param content [Nokogiri::XML::Document]
|
|
24
|
+
# @return [RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliongraphicItem]
|
|
25
|
+
def self.parse_xml(doc)
|
|
26
|
+
if (processor = Relaton::Registry.instance.by_type(Relaton::Cli.doctype(doc)))
|
|
27
|
+
processor.from_xml(doc.to_s)
|
|
28
|
+
else
|
|
29
|
+
RelatonBib::XMLParser.from_xml(doc.to_s)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @param content [Nokogiri::XML::Document] Document
|
|
34
|
+
# @return [String] Type prefix
|
|
35
|
+
def self.doctype(doc)
|
|
36
|
+
docid = doc.at "docidentifier"
|
|
37
|
+
return docid[:type] if docid && docid[:type]
|
|
38
|
+
|
|
39
|
+
docid&.text&.match(/^\w+/)&.to_s
|
|
40
|
+
end
|
|
22
41
|
end
|
|
23
42
|
end
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "fileutils"
|
|
2
2
|
require "relaton/bibdata"
|
|
3
|
+
require "relaton/bibdatanew"
|
|
3
4
|
require "relaton/bibcollection"
|
|
4
5
|
require "relaton/bibcollectionnew"
|
|
5
6
|
require "relaton/cli/xml_to_html_renderer"
|
|
@@ -107,9 +108,9 @@ module Relaton
|
|
|
107
108
|
def extract_docid(item)
|
|
108
109
|
@default_filelabel += 1
|
|
109
110
|
item.docidentifier.nil? and return @default_filelabel.to_s
|
|
110
|
-
item.docidentifier.is_a?(Array) or return @default_filelabel.to_s
|
|
111
|
+
# item.docidentifier.is_a?(Array) or return @default_filelabel.to_s
|
|
111
112
|
item.docidentifier.empty? and return @default_filelabel.to_s
|
|
112
|
-
docidentifier_code(item.docidentifier
|
|
113
|
+
docidentifier_code(item.docidentifier)
|
|
113
114
|
end
|
|
114
115
|
|
|
115
116
|
# From http://gavinmiller.io/2016/creating-a-secure-sanitization-function/
|
data/lib/relaton/cli/command.rb
CHANGED
|
@@ -28,6 +28,7 @@ module Relaton
|
|
|
28
28
|
desc "concatenate SOURCE-DIR COLLECTION-FILE", "Concatenate entries in DIRECTORY (containing Relaton-XML or YAML) into a Relaton Collection"
|
|
29
29
|
option :title, aliases: :t, desc: "Title of resulting Relaton collection"
|
|
30
30
|
option :organization, aliases: :g, desc: "Organization owner of Relaton collection"
|
|
31
|
+
option :new, aliases: :n, type: :boolean, desc: "Use the new Relaton YAML format"
|
|
31
32
|
|
|
32
33
|
def concatenate(source_dir, outfile)
|
|
33
34
|
Relaton::Cli::RelatonFile.concatenate(source_dir, outfile, options)
|
|
@@ -35,6 +36,7 @@ module Relaton
|
|
|
35
36
|
|
|
36
37
|
desc "split Relaton-Collection-File Relaton-XML-Directory", "Split a Relaton Collection into multiple files"
|
|
37
38
|
option :extension, aliases: :x, desc: "File extension of Relaton XML files, defaults to 'rxl'"
|
|
39
|
+
option :new, aliases: :n, type: :boolean, desc: "Use the new Relaton YAML format"
|
|
38
40
|
|
|
39
41
|
def split(source, outdir)
|
|
40
42
|
Relaton::Cli::RelatonFile.split(source, outdir, options)
|
|
@@ -16,7 +16,7 @@ module Relaton
|
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def concatenate
|
|
19
|
-
write_to_file(bibcollection.to_xml)
|
|
19
|
+
write_to_file(bibcollection.to_xml(options))
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def split
|
|
@@ -81,7 +81,7 @@ module Relaton
|
|
|
81
81
|
attr_reader :source, :options, :outdir, :outfile
|
|
82
82
|
|
|
83
83
|
def bibcollection
|
|
84
|
-
|
|
84
|
+
bib_klass.new(
|
|
85
85
|
title: options[:title],
|
|
86
86
|
items: concatenate_files,
|
|
87
87
|
doctype: options[:doctype],
|
|
@@ -103,8 +103,7 @@ module Relaton
|
|
|
103
103
|
end
|
|
104
104
|
|
|
105
105
|
def relaton_collection
|
|
106
|
-
@relaton_collection ||=
|
|
107
|
-
Relaton::Bibcollection.from_xml(nokogiri_document(nil, source))
|
|
106
|
+
@relaton_collection ||= bib_klass.from_xml(nokogiri_document(nil, source))
|
|
108
107
|
end
|
|
109
108
|
|
|
110
109
|
def extract_and_write_to_files
|
|
@@ -172,16 +171,30 @@ module Relaton
|
|
|
172
171
|
|
|
173
172
|
def bibdata_instance(document, file)
|
|
174
173
|
document = clean_nokogiri_document(document)
|
|
175
|
-
bibdata =
|
|
174
|
+
bibdata = if options[:new]
|
|
175
|
+
Relaton::BibdataNew.from_xml document.root
|
|
176
|
+
else
|
|
177
|
+
Relaton::Bibdata.from_xml(document.root)
|
|
178
|
+
end
|
|
176
179
|
build_bibdata_relaton(bibdata, file)
|
|
177
180
|
|
|
178
181
|
bibdata
|
|
179
182
|
end
|
|
180
183
|
|
|
184
|
+
# @param content [Nokogiri::XML::Document]
|
|
185
|
+
# @return [Hash]
|
|
186
|
+
def parse_doc(doc)
|
|
187
|
+
if (processor = Relaton::Registry.instance.by_type(doctype(doc)))
|
|
188
|
+
processor.from_xml(doc.to_s).to_hash
|
|
189
|
+
else
|
|
190
|
+
RelatonBib::XMLParser.from_xml(doc.to_s).to_hash
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
181
194
|
def build_bibdata_relaton(bibdata, file)
|
|
182
195
|
["xml", "pdf", "doc", "html", "rxl", "txt"].each do |type|
|
|
183
196
|
file = Pathname.new(file).sub_ext(".#{type}")
|
|
184
|
-
bibdata.send("#{type}=", file) if File.file?(file)
|
|
197
|
+
bibdata.send("#{type}=", file.to_s) if File.file?(file)
|
|
185
198
|
end
|
|
186
199
|
end
|
|
187
200
|
|
|
@@ -203,8 +216,9 @@ module Relaton
|
|
|
203
216
|
end
|
|
204
217
|
|
|
205
218
|
def convert_yamls_to_xml
|
|
219
|
+
klass = options[:new] ? YAMLConvertorNew : YAMLConvertor
|
|
206
220
|
select_files_with("yaml").map do |file|
|
|
207
|
-
{ file: file, content:
|
|
221
|
+
{ file: file, content: klass.to_xml(file, write: false) }
|
|
208
222
|
end
|
|
209
223
|
end
|
|
210
224
|
|
|
@@ -233,7 +247,7 @@ module Relaton
|
|
|
233
247
|
end
|
|
234
248
|
|
|
235
249
|
def build_filename(file, identifier = nil, ext = "rxl")
|
|
236
|
-
identifier ||= Pathname.new(File.basename(file, ".xml")).to_s
|
|
250
|
+
identifier ||= Pathname.new(File.basename(file.to_s, ".xml")).to_s
|
|
237
251
|
[sanitize_string(identifier), options[:extension] || ext].join(".")
|
|
238
252
|
end
|
|
239
253
|
|
|
@@ -246,6 +260,10 @@ module Relaton
|
|
|
246
260
|
bad_chars = ["/", "\\", "?", "%", "*", ":", "|", '"', "<", ">", ".", " "]
|
|
247
261
|
bad_chars.inject(string.downcase) { |res, char| res.gsub(char, "-") }
|
|
248
262
|
end
|
|
263
|
+
|
|
264
|
+
def bib_klass
|
|
265
|
+
@bib_klass ||= options[:new] ? Relaton::BibcollectionNew : Relaton::Bibcollection
|
|
266
|
+
end
|
|
249
267
|
end
|
|
250
268
|
end
|
|
251
269
|
end
|
data/lib/relaton/cli/version.rb
CHANGED
|
@@ -34,7 +34,7 @@ module Relaton
|
|
|
34
34
|
def convert_content(content)
|
|
35
35
|
if content.root.name == "bibdata"
|
|
36
36
|
# Bibdata.from_xml(content.to_s)
|
|
37
|
-
|
|
37
|
+
Relaton::Cli.parse_xml(content).to_hash
|
|
38
38
|
else
|
|
39
39
|
# Bibcollection.from_xml(content)
|
|
40
40
|
title = content.at("relaton-collection/title").text
|
|
@@ -42,32 +42,13 @@ module Relaton
|
|
|
42
42
|
collection = { "root" => { "title" => title, "author" => author } }
|
|
43
43
|
|
|
44
44
|
collection["root"]["items"] = content.xpath("//bibdata").map do |bib|
|
|
45
|
-
|
|
45
|
+
Relaton::Cli.parse_xml(bib).to_hash
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
collection
|
|
49
49
|
end
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
# @param content [Nokogiri::XML::Document]
|
|
53
|
-
# @return [Hash]
|
|
54
|
-
def convert_bibdata(doc)
|
|
55
|
-
if (processor = Relaton::Registry.instance.by_type(doctype(doc)))
|
|
56
|
-
processor.from_xml(doc.to_s).to_hash
|
|
57
|
-
else
|
|
58
|
-
RelatonBib::XMLParser.from_xml(doc.to_s).to_hash
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
# @param content [Nokogiri::XML::Document]
|
|
63
|
-
# @return [String]
|
|
64
|
-
def doctype(doc)
|
|
65
|
-
docid = doc.at "//docidentifier"
|
|
66
|
-
return docid[:type] if docid && docid[:type]
|
|
67
|
-
|
|
68
|
-
docid.text.match(/^\w+/).to_s
|
|
69
|
-
end
|
|
70
|
-
|
|
71
52
|
def file_content
|
|
72
53
|
Nokogiri::XML(File.read(file, encoding: "utf-8")).remove_namespaces!
|
|
73
54
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: relaton-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.7
|
|
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-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -222,6 +222,7 @@ files:
|
|
|
222
222
|
- lib/relaton/bibcollection.rb
|
|
223
223
|
- lib/relaton/bibcollectionnew.rb
|
|
224
224
|
- lib/relaton/bibdata.rb
|
|
225
|
+
- lib/relaton/bibdatanew.rb
|
|
225
226
|
- lib/relaton/cli.rb
|
|
226
227
|
- lib/relaton/cli/_document.liquid
|
|
227
228
|
- lib/relaton/cli/_index.liquid
|