relaton-core 0.0.11 → 0.0.12
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/core/data_fetcher.rb +74 -72
- data/lib/relaton/core/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9dead65db427dc877d76ca902de6a029447fca540a79fd906817acc38b3e79ba
|
|
4
|
+
data.tar.gz: 6c8fa5f6bfe487660cfbba79d0a0496ace2d22afc28cf99e6aa75a3452b71b25
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5e5a7584b4d7dfa733f474d860b5d549cbf766e726863a986b42c47bc5ffcc377b243a687a5178cdc55c39e49fccc390b1995dd0149aeba1a02668a7f90a1b94
|
|
7
|
+
data.tar.gz: acc985743c00f072b50f8a3cc16336a8f717dba9ff3a6aa48a9fdaa59bc4fbff5655f2b3db1c3e41ff54fab33f5bb55785024e8f0b66dd08132850c4ba2fd7e6
|
|
@@ -1,90 +1,92 @@
|
|
|
1
1
|
require "fileutils"
|
|
2
2
|
|
|
3
|
-
module Relaton
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
module Relaton
|
|
4
|
+
module Core
|
|
5
|
+
class DataFetcher
|
|
6
|
+
# attr_accessor :docs
|
|
7
|
+
#
|
|
8
|
+
# Initialize fetcher
|
|
9
|
+
#
|
|
10
|
+
# @param [String] output path to output directory
|
|
11
|
+
# @param [String] format output format (yaml, xml, bibxml)
|
|
12
|
+
#
|
|
13
|
+
def initialize(output, format)
|
|
14
|
+
@output = output
|
|
15
|
+
@format = format
|
|
16
|
+
@ext = format.sub "bibxml", "xml"
|
|
17
|
+
@files = Set.new
|
|
18
|
+
# @docs = []
|
|
19
|
+
@errors = Hash.new(true)
|
|
20
|
+
end
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
# API method for external service
|
|
23
|
+
def self.fetch(source = nil, output: "data", format: "yaml")
|
|
24
|
+
t1 = Time.now
|
|
25
|
+
puts "Started at: #{t1}"
|
|
26
|
+
FileUtils.mkdir_p output
|
|
27
|
+
new(output, format).fetch(source)
|
|
28
|
+
t2 = Time.now
|
|
29
|
+
puts "Stopped at: #{t2}"
|
|
30
|
+
puts "Done in: #{(t2 - t1).round} sec."
|
|
31
|
+
end
|
|
31
32
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
def fetch(source = nil)
|
|
34
|
+
raise NotImplementedError, "#{self.class}#fetch method must be implemented"
|
|
35
|
+
end
|
|
35
36
|
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
def gh_issue
|
|
38
|
+
return @gh_issue if defined? @gh_issue
|
|
38
39
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
40
|
+
channel = gh_issue_channel
|
|
41
|
+
if channel[0]
|
|
42
|
+
@gh_issue = Relaton::Logger::Channels::GhIssue.new(*channel)
|
|
43
|
+
Relaton.logger_pool[:gh_issue] = Relaton::Logger::Log.new(@gh_issue, levels: [:error])
|
|
44
|
+
end
|
|
45
|
+
@gh_issue
|
|
43
46
|
end
|
|
44
|
-
@gh_issue
|
|
45
|
-
end
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
def gh_issue_channel
|
|
49
|
+
[ENV.fetch("GITHUB_REPOSITORY", nil), "Error fetching documents"]
|
|
50
|
+
end
|
|
50
51
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
def report_errors
|
|
53
|
+
gh_issue # register the channel before logging
|
|
54
|
+
@errors.select { |_, v| v }.each_key { |k| log_error "Failed to fetch #{k}" }
|
|
55
|
+
@gh_issue&.create_issue
|
|
56
|
+
end
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
def log_error(_msg)
|
|
59
|
+
raise NoMatchingPatternError, "#{self.class}#log_error method must be implemented"
|
|
60
|
+
end
|
|
60
61
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
62
|
+
# @param [String] document ID
|
|
63
|
+
# @return [String] filename based on PubID identifier
|
|
64
|
+
def output_file(docid)
|
|
65
|
+
File.join @output, "#{docid.downcase.gsub(/[.\s\/:-]+/, '-')}.#{@ext}"
|
|
66
|
+
end
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
68
|
+
#
|
|
69
|
+
# Serialize bibliographic item
|
|
70
|
+
#
|
|
71
|
+
# @param [RelatonCcsds::BibliographicItem] bib <description>
|
|
72
|
+
#
|
|
73
|
+
# @return [String] serialized bibliographic item
|
|
74
|
+
#
|
|
75
|
+
def serialize(bib)
|
|
76
|
+
send "to_#{@format}", bib
|
|
77
|
+
end
|
|
77
78
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
def to_yaml(bib)
|
|
80
|
+
raise NotImplementedError, "#{self.class}#to_yaml method must be implemented"
|
|
81
|
+
end
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
def to_xml(bib)
|
|
84
|
+
raise NotImplementedError, "#{self.class}#to_xml method must be implemented"
|
|
85
|
+
end
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
def to_bibxml(bib)
|
|
88
|
+
raise NotImplementedError, "#{self.class}#to_bibxml method must be implemented"
|
|
89
|
+
end
|
|
88
90
|
end
|
|
89
91
|
end
|
|
90
92
|
end
|
data/lib/relaton/core/version.rb
CHANGED