relaton-cli 1.2.0 → 1.2.1
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/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/yaml_convertor.rb +57 -43
- 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: 8a02348a5d77b33a2e249bc4aa1a22ed07d8fff2cfdb5323799abc9cc0d0a445
|
4
|
+
data.tar.gz: e4ba64c5d0d8e5db5ad4e7b3a7be42a13e7bfc22c2beb81336391decb96853b0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee47c92805a92f72e5a23b554cc8a5737f38392b33a64f9a3d36f6732b61958052ae493a9e2bd0cbb02b2854bf9b453e6b68b82182c4907c9d90e64af7867331
|
7
|
+
data.tar.gz: 6bac8c0e2f42e093ca23592d7ac908f86389907125d9f39400c6a8c562b322809ca06f9134ffbdacc5b7cb50313438c447d0f7b142c4de400b498a1b07c1937a
|
data/lib/relaton/cli/version.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require 'yaml'
|
2
|
+
require 'relaton/cli/base_convertor'
|
3
|
+
require 'relaton_bib'
|
4
4
|
|
5
5
|
module Relaton
|
6
6
|
module Cli
|
@@ -9,29 +9,55 @@ module Relaton
|
|
9
9
|
if writable
|
10
10
|
convert_and_write(file_content, :to_xml)
|
11
11
|
else
|
12
|
-
convert_content(file_content).to_xml
|
12
|
+
convert_content(file_content).to_xml date_format: :full, bibdata: true
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
16
|
+
class << self
|
17
|
+
# Convert to XML
|
18
|
+
#
|
19
|
+
# This interface allow us to convert any YAML file to XML.
|
20
|
+
# It only require us to provide a valid YAML file and it can
|
21
|
+
# do converstion using default attributes, but it also allow
|
22
|
+
# us to provide custom options to customize this converstion
|
23
|
+
# process.
|
24
|
+
#
|
25
|
+
# @param file [File] The complete path to a YAML file
|
26
|
+
# @param options [Hash] Options as hash key, value pairs.
|
27
|
+
#
|
28
|
+
def to_xml(file, options = {})
|
29
|
+
new(file, options).to_xml
|
30
|
+
end
|
31
|
+
|
32
|
+
# @param content [Hash] document in YAML format
|
33
|
+
# @return [RelatonBib::BibliographicItem,
|
34
|
+
# RelatonIso::IsoBiblioraphicItem]
|
35
|
+
def convert_single_file(content)
|
36
|
+
if (processor = Registry.instance.by_type(doctype(content['docid'])))
|
37
|
+
processor.hash_to_bib content
|
38
|
+
else
|
39
|
+
RelatonBib::BibliographicItem.new(
|
40
|
+
RelatonBib::HashConverter::hash_to_bib(content)
|
41
|
+
)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# @param content [Hash]
|
48
|
+
# @return [String]
|
49
|
+
def doctype(docid)
|
50
|
+
did = docid.is_a?(Array) ? docid.fetch(0) : docid
|
51
|
+
return unless did
|
52
|
+
|
53
|
+
did['type'] || did.fetch('id')&.match(/^\w+/)&.to_s
|
54
|
+
end
|
29
55
|
end
|
30
56
|
|
31
57
|
private
|
32
58
|
|
33
59
|
def default_ext
|
34
|
-
|
60
|
+
'rxl'
|
35
61
|
end
|
36
62
|
|
37
63
|
def file_content
|
@@ -39,37 +65,25 @@ module Relaton
|
|
39
65
|
end
|
40
66
|
|
41
67
|
def date_to_string(obj)
|
42
|
-
obj.is_a? Hash
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
def convert_single_file(content)
|
50
|
-
if (processor = Relaton::Registry.instance.by_type(doctype(content["docid"])))
|
51
|
-
processor.hash_to_bib content
|
68
|
+
if obj.is_a? Hash
|
69
|
+
obj.reduce({}) do |memo, (k, v)|
|
70
|
+
memo[k] = date_to_string(v)
|
71
|
+
memo
|
72
|
+
end
|
73
|
+
elsif obj.is_a? Array
|
74
|
+
obj.reduce([]) { |memo, v| memo << date_to_string(v) }
|
52
75
|
else
|
53
|
-
|
76
|
+
obj.is_a?(Date) ? obj.to_s : obj
|
54
77
|
end
|
55
78
|
end
|
56
79
|
|
57
|
-
# @param content [Hash]
|
58
|
-
# @return [String]
|
59
|
-
def doctype(docid)
|
60
|
-
did = docid.is_a?(Array) ? docid.fetch(0) : docid
|
61
|
-
return did["type"] if did && did["type"]
|
62
|
-
|
63
|
-
did&.fetch("id")&.match(/^\w+/)&.to_s
|
64
|
-
end
|
65
|
-
|
66
80
|
def convert_collection(content)
|
67
|
-
if content.has_key?(
|
68
|
-
content[
|
81
|
+
if content.has_key?('root')
|
82
|
+
content['root']['items'] = content['root']['items'].map do |i|
|
69
83
|
# RelatonBib::HashConverter::hash_to_bib(i)
|
70
|
-
convert_single_file(i)
|
84
|
+
self.class.convert_single_file(i)
|
71
85
|
end
|
72
|
-
Relaton::Bibcollection.new(content[
|
86
|
+
Relaton::Bibcollection.new(content['root'])
|
73
87
|
end
|
74
88
|
end
|
75
89
|
|
@@ -78,7 +92,7 @@ module Relaton
|
|
78
92
|
end
|
79
93
|
|
80
94
|
def convert_content(content)
|
81
|
-
convert_collection(content) || convert_single_file(content)
|
95
|
+
convert_collection(content) || self.class.convert_single_file(content)
|
82
96
|
end
|
83
97
|
end
|
84
98
|
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: 1.2.
|
4
|
+
version: 1.2.1
|
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-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: byebug
|