relaton-cli 1.1.1 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/lib/relaton/bibcollection.rb +1 -1
- data/lib/relaton/bibdata.rb +6 -18
- data/lib/relaton/cli.rb +9 -7
- data/lib/relaton/cli/command.rb +1 -1
- data/lib/relaton/cli/relaton_file.rb +12 -13
- data/lib/relaton/cli/version.rb +1 -1
- data/lib/relaton/cli/xml_convertor.rb +0 -10
- data/lib/relaton/cli/yaml_convertor.rb +57 -43
- data/relaton-cli.gemspec +2 -2
- data/templates/_document.liquid +1 -1
- metadata +6 -6
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/.gitignore
CHANGED
@@ -41,7 +41,7 @@ module Relaton
|
|
41
41
|
)
|
42
42
|
|
43
43
|
items = find_xpath("./relaton-collection/relation", source)&.map do |item|
|
44
|
-
bibdata = find("./bibdata", item)
|
44
|
+
bibdata = find("./bibdata|./bibitem", item)
|
45
45
|
klass = bibdata ? Bibdata : Bibcollection
|
46
46
|
klass.from_xml(bibdata || item)
|
47
47
|
end
|
data/lib/relaton/bibdata.rb
CHANGED
@@ -10,18 +10,6 @@ module Relaton
|
|
10
10
|
@bibitem = bibitem
|
11
11
|
end
|
12
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
13
|
def docidentifier
|
26
14
|
@bibitem.docidentifier.first&.id
|
27
15
|
end
|
@@ -57,15 +45,10 @@ module Relaton
|
|
57
45
|
opts.select { |k, _v| k.is_a? Symbol },
|
58
46
|
)
|
59
47
|
@bibitem.to_xml nil, **options
|
60
|
-
|
61
|
-
# #datetype = stage&.casecmp("published") == 0 ? "published" : "circulated"
|
62
|
-
|
63
|
-
# ret = ref ? "<bibitem id= '#{ref}' type='#{doctype}'>\n" : "<bibdata type='#{doctype}'>\n"
|
64
|
-
# ret += "<fetched>#{Date.today.to_s}</fetched>\n"
|
65
48
|
end
|
66
49
|
|
67
50
|
def to_h
|
68
|
-
URL_TYPES.reduce(
|
51
|
+
URL_TYPES.reduce(@bibitem.to_hash) do |h, t|
|
69
52
|
value = send t
|
70
53
|
h[t.to_s] = value
|
71
54
|
h
|
@@ -76,6 +59,9 @@ module Relaton
|
|
76
59
|
to_h.to_yaml
|
77
60
|
end
|
78
61
|
|
62
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
63
|
+
# rubocop:disable Metrics/MethodLength, Metrics/PerceivedComplexity, Style/MissingRespondToMissing
|
64
|
+
|
79
65
|
def method_missing(meth, *args)
|
80
66
|
if @bibitem.respond_to?(meth)
|
81
67
|
@bibitem.send meth, *args
|
@@ -98,5 +84,7 @@ module Relaton
|
|
98
84
|
super
|
99
85
|
end
|
100
86
|
end
|
87
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/AbcSize
|
88
|
+
# rubocop:enable Metrics/MethodLength, Metrics/PerceivedComplexity, Style/MissingRespondToMissing
|
101
89
|
end
|
102
90
|
end
|
data/lib/relaton/cli.rb
CHANGED
@@ -34,20 +34,22 @@ module Relaton
|
|
34
34
|
# @param content [Nokogiri::XML::Document]
|
35
35
|
# @return [RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliongraphicItem]
|
36
36
|
def self.parse_xml(doc)
|
37
|
-
if (
|
38
|
-
|
37
|
+
if (proc = Cli.processor(doc))
|
38
|
+
proc.from_xml(doc.to_s)
|
39
39
|
else
|
40
40
|
RelatonBib::XMLParser.from_xml(doc.to_s)
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
-
# @param
|
44
|
+
# @param doc [Nokogiri::XML::Element]
|
45
45
|
# @return [String] Type prefix
|
46
|
-
def self.
|
46
|
+
def self.processor(doc)
|
47
47
|
docid = doc.at "docidentifier"
|
48
|
-
|
49
|
-
|
50
|
-
|
48
|
+
if docid && docid[:type]
|
49
|
+
proc = Relaton::Registry.instance.by_type(docid[:type])
|
50
|
+
return proc if proc
|
51
|
+
end
|
52
|
+
Relaton::Registry.instance.by_type(docid&.text&.match(/^\w+/)&.to_s)
|
51
53
|
end
|
52
54
|
end
|
53
55
|
end
|
data/lib/relaton/cli/command.rb
CHANGED
@@ -28,7 +28,7 @@ module Relaton
|
|
28
28
|
option :title, aliases: :t, desc: "Title of resulting Relaton collection"
|
29
29
|
option :organization, aliases: :g, desc: "Organization owner of Relaton collection"
|
30
30
|
option :new, aliases: :n, type: :boolean, desc: "Use the new Relaton YAML format"
|
31
|
-
option :extension, aliases: :x,
|
31
|
+
option :extension, aliases: :x, desc: "File extension of destination Relaton file, defaults to 'rxl'"
|
32
32
|
|
33
33
|
def concatenate(source_dir, outfile)
|
34
34
|
Relaton::Cli::RelatonFile.concatenate(source_dir, outfile, options)
|
@@ -118,7 +118,6 @@ module Relaton
|
|
118
118
|
bib = nokogiri_document(bib.to_xml)
|
119
119
|
elsif (rfc = xml.at("//rfc"))
|
120
120
|
require "relaton_ietf/scrapper"
|
121
|
-
#ietf = RelatonIetf::Scrapper.bib_item rfc, "rfc"
|
122
121
|
ietf = RelatonIetf::Scrapper.fetch_rfc rfc
|
123
122
|
bib = nokogiri_document ietf.to_xml(bibdata: true)
|
124
123
|
else
|
@@ -142,18 +141,16 @@ module Relaton
|
|
142
141
|
|
143
142
|
xml_files.flatten.reduce([]) do |mem, xml|
|
144
143
|
doc = nokogiri_document(xml[:content])
|
145
|
-
if (
|
144
|
+
if (rfc = doc.at("/rfc"))
|
146
145
|
require "relaton_ietf/scrapper"
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
end
|
152
|
-
elsif doc&.root&.name == "bibdata"
|
146
|
+
ietf = RelatonIetf::Scrapper.fetch_rfc rfc
|
147
|
+
d = nokogiri_document ietf.to_xml(bibdata: true)
|
148
|
+
mem << bibdata_instance(d, xml[:file])
|
149
|
+
elsif %w[bibitem bibdata].include? doc&.root&.name
|
153
150
|
mem << bibdata_instance(doc, xml[:file])
|
154
151
|
else mem
|
155
152
|
end
|
156
|
-
end.
|
153
|
+
end.uniq &:id
|
157
154
|
end
|
158
155
|
|
159
156
|
def concatenate_and_write_to_files
|
@@ -170,21 +167,23 @@ module Relaton
|
|
170
167
|
end
|
171
168
|
end
|
172
169
|
|
173
|
-
def find_available_bibrxl_file(name,
|
170
|
+
def find_available_bibrxl_file(name, _ouputdir, content)
|
174
171
|
if options[:extension] == "yaml" || options[:extension] == "yml"
|
175
172
|
bib_rxl = Pathname.new([outdir, name].join("/")).sub_ext(".rxl")
|
176
173
|
content.bib_rxl = bib_rxl.to_s if File.file?(bib_rxl)
|
177
174
|
end
|
178
175
|
end
|
179
176
|
|
180
|
-
def output_type(ext=options[:extension])
|
177
|
+
def output_type(ext = options[:extension])
|
178
|
+
ext ||= File.extname(outfile)[1..-1] if outfile
|
181
179
|
case ext
|
182
180
|
when "rxl", "xml"
|
183
181
|
:to_xml
|
184
182
|
when "yml", "yaml"
|
185
183
|
:to_yaml
|
186
184
|
else
|
187
|
-
puts "[relaton-cli] the given extension of '#{ext}' is
|
185
|
+
puts "[relaton-cli] the given extension of '#{ext}' is "\
|
186
|
+
"not supported. Use 'rxl'."
|
188
187
|
:to_xml
|
189
188
|
end
|
190
189
|
end
|
@@ -270,7 +269,7 @@ module Relaton
|
|
270
269
|
|
271
270
|
def replace_bad_characters(string)
|
272
271
|
bad_chars = ["/", "\\", "?", "%", "*", ":", "|", '"', "<", ">", ".", " "]
|
273
|
-
bad_chars.
|
272
|
+
bad_chars.reduce(string.downcase) { |res, char| res.gsub(char, "-") }
|
274
273
|
end
|
275
274
|
end
|
276
275
|
end
|
data/lib/relaton/cli/version.rb
CHANGED
@@ -34,18 +34,8 @@ module Relaton
|
|
34
34
|
def convert_content(content)
|
35
35
|
if %w[bibitem bibdata].include? content.root.name
|
36
36
|
Bibdata.from_xml(content)
|
37
|
-
# Relaton::Cli.parse_xml(content).to_hash
|
38
37
|
else
|
39
38
|
Bibcollection.from_xml(content)
|
40
|
-
# title = content.at("relaton-collection/title").text
|
41
|
-
# author = content.at("relaton-collection/contributor/organization/name").text
|
42
|
-
# collection = { "root" => { "title" => title, "author" => author } }
|
43
|
-
|
44
|
-
# collection["root"]["items"] = content.xpath("//bibdata").map do |bib|
|
45
|
-
# Relaton::Cli.parse_xml(bib).to_hash
|
46
|
-
# end
|
47
|
-
|
48
|
-
# collection
|
49
39
|
end
|
50
40
|
end
|
51
41
|
|
@@ -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
|
data/relaton-cli.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.require_paths = ["lib"]
|
23
23
|
spec.required_ruby_version = ">= 2.4.0"
|
24
24
|
|
25
|
-
spec.add_development_dependency "byebug", "~>
|
25
|
+
spec.add_development_dependency "byebug", "~> 11.0"
|
26
26
|
spec.add_development_dependency "debase"
|
27
27
|
spec.add_development_dependency "equivalent-xml", "~> 0.6"
|
28
28
|
spec.add_development_dependency "pry"
|
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
spec.add_development_dependency "simplecov"
|
35
35
|
|
36
36
|
spec.add_runtime_dependency "liquid"
|
37
|
-
spec.add_runtime_dependency "relaton", "~> 1.
|
37
|
+
spec.add_runtime_dependency "relaton", "~> 1.2.0"
|
38
38
|
spec.add_runtime_dependency "thor"
|
39
39
|
# spec.add_runtime_dependency 'byebug'
|
40
40
|
end
|
data/templates/_document.liquid
CHANGED
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.
|
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
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '11.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '11.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: debase
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,14 +170,14 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - "~>"
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: 1.
|
173
|
+
version: 1.2.0
|
174
174
|
type: :runtime
|
175
175
|
prerelease: false
|
176
176
|
version_requirements: !ruby/object:Gem::Requirement
|
177
177
|
requirements:
|
178
178
|
- - "~>"
|
179
179
|
- !ruby/object:Gem::Version
|
180
|
-
version: 1.
|
180
|
+
version: 1.2.0
|
181
181
|
- !ruby/object:Gem::Dependency
|
182
182
|
name: thor
|
183
183
|
requirement: !ruby/object:Gem::Requirement
|