relaton-cli 1.2.0 → 1.2.1

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: 123355f5af7996292e76a60dc07f46fa5593737d18b1453686a5750201d8be05
4
- data.tar.gz: 2b67ff870e9111433388706fad09c93b53d1c16799745879080aa4dddbadd5f5
3
+ metadata.gz: 8a02348a5d77b33a2e249bc4aa1a22ed07d8fff2cfdb5323799abc9cc0d0a445
4
+ data.tar.gz: e4ba64c5d0d8e5db5ad4e7b3a7be42a13e7bfc22c2beb81336391decb96853b0
5
5
  SHA512:
6
- metadata.gz: dab4b72334270f2e6d89a1321aa8dda62704b2098d0f992baca667c70caa0d65c72cb35d90a23e697fd57476387fd76eb06a1740acd9376c84dbb49af032de44
7
- data.tar.gz: 922783e332d69cccffce0f2dc17edfe40f3f3d27697589ac41b14d04108ecd4a9db92551e57c38f6d73384f8b286ed185d61e1fc04077821ba0b2eb542095b88
6
+ metadata.gz: ee47c92805a92f72e5a23b554cc8a5737f38392b33a64f9a3d36f6732b61958052ae493a9e2bd0cbb02b2854bf9b453e6b68b82182c4907c9d90e64af7867331
7
+ data.tar.gz: 6bac8c0e2f42e093ca23592d7ac908f86389907125d9f39400c6a8c562b322809ca06f9134ffbdacc5b7cb50313438c447d0f7b142c4de400b498a1b07c1937a
@@ -1,5 +1,5 @@
1
1
  module Relaton
2
2
  module Cli
3
- VERSION = "1.2.0".freeze
3
+ VERSION = "1.2.1".freeze
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
- require "yaml"
2
- require "relaton/cli/base_convertor"
3
- require "relaton_bib"
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(date_format: :full, bibdata: true)
12
+ convert_content(file_content).to_xml date_format: :full, bibdata: true
13
13
  end
14
14
  end
15
15
 
16
- # Convert to XML
17
- #
18
- # This interface allow us to convert any YAML file to XML.
19
- # It only require us to provide a valid YAML file and it can
20
- # do converstion using default attributes, but it also allow
21
- # us to provide custom options to customize this converstion
22
- # process.
23
- #
24
- # @param file [File] The complete path to a YAML file
25
- # @param options [Hash] Options as hash key, value pairs.
26
- #
27
- def self.to_xml(file, options = {})
28
- new(file, options).to_xml
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
- "rxl"
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 and
43
- return obj.inject({}){|memo,(k,v)| memo[k] = date_to_string(v); memo}
44
- obj.is_a? Array and
45
- return obj.inject([]){|memo,v | memo << date_to_string(v); memo}
46
- return obj.is_a?(Date) ? obj.to_s : obj
47
- end
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
- RelatonBib::BibliographicItem.new(RelatonBib::HashConverter::hash_to_bib(content))
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?("root")
68
- content["root"]["items"] = content["root"]["items"].map do |i|
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["root"])
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.0
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-06-26 00:00:00.000000000 Z
11
+ date: 2020-07-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug