Class: Relaton::Core::DataFetcher
- Inherits:
-
Object
- Object
- Relaton::Core::DataFetcher
show all
- Defined in:
- lib/relaton/core/data_fetcher.rb
Direct Known Subclasses
Bipm::DataFetcher, Relaton::Calconnect::DataFetcher, Relaton::Ccsds::DataFetcher, Relaton::Cie::DataFetcher, Ecma::DataFetcher, Etsi::DataFetcher, Iana::DataFetcher, Iec::DataFetcher, Ieee::DataFetcher, Ietf::DataFetcher, Iso::DataFetcher, Itu::DataFetcher, Jis::DataFetcher, Nist::DataFetcher, Oasis::DataFetcher, Ogc::DataFetcher, Plateau::DataFetcher, ThreeGpp::DataFetcher, W3c::DataFetcher, Xsf::DataFetcher
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(output, format) ⇒ DataFetcher
attr_accessor :docs
Initialize fetcher
13
14
15
16
17
18
19
20
|
# File 'lib/relaton/core/data_fetcher.rb', line 13
def initialize(output, format)
@output = output
@format = format
@ext = format.sub "bibxml", "xml"
@files = Set.new
@errors = Hash.new(true)
end
|
Class Method Details
.fetch(source = nil, output: "data", format: "yaml") ⇒ Object
API method for external service
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/relaton/core/data_fetcher.rb', line 26
def self.fetch(source = nil, output: "data", format: "yaml")
t1 = Time.now
puts "Started at: #{t1}"
FileUtils.mkdir_p output
result = new(output, format).fetch(source)
t2 = Time.now
puts "Stopped at: #{t2}"
puts "Done in: #{(t2 - t1).round} sec."
result
end
|
Instance Method Details
#fetch(source = nil) ⇒ Object
37
38
39
|
# File 'lib/relaton/core/data_fetcher.rb', line 37
def fetch(source = nil)
raise NotImplementedError, "#{self.class}#fetch method must be implemented"
end
|
#gh_issue_channel ⇒ Object
52
53
54
|
# File 'lib/relaton/core/data_fetcher.rb', line 52
def gh_issue_channel
[ENV.fetch("GITHUB_REPOSITORY", nil), "Error fetching documents"]
end
|
#log_error(_msg) ⇒ Object
62
63
64
|
# File 'lib/relaton/core/data_fetcher.rb', line 62
def log_error(_msg)
raise NoMatchingPatternError, "#{self.class}#log_error method must be implemented"
end
|
#output_file(docid) ⇒ String
Returns filename based on PubID identifier.
68
69
70
71
|
# File 'lib/relaton/core/data_fetcher.rb', line 68
def output_file(docid)
id = docid.downcase.gsub(/[.\s\/:()-]+/, "-").delete_suffix("-")
File.join @output, "#{id}.#{@ext}"
end
|
#report_errors ⇒ Object
56
57
58
59
60
|
# File 'lib/relaton/core/data_fetcher.rb', line 56
def report_errors
gh_issue @errors.select { |_, v| v }.each_key { |k| log_error "Failed to fetch #{k}" }
@gh_issue&.create_issue
end
|
#serialize(bib) ⇒ String
Serialize bibliographic item
80
81
82
|
# File 'lib/relaton/core/data_fetcher.rb', line 80
def serialize(bib)
send "to_#{@format}", bib
end
|
#to_bibxml(bib) ⇒ Object
92
93
94
|
# File 'lib/relaton/core/data_fetcher.rb', line 92
def to_bibxml(bib)
raise NotImplementedError, "#{self.class}#to_bibxml method must be implemented"
end
|
#to_xml(bib) ⇒ Object
88
89
90
|
# File 'lib/relaton/core/data_fetcher.rb', line 88
def to_xml(bib)
raise NotImplementedError, "#{self.class}#to_xml method must be implemented"
end
|
#to_yaml(bib) ⇒ Object
84
85
86
|
# File 'lib/relaton/core/data_fetcher.rb', line 84
def to_yaml(bib)
raise NotImplementedError, "#{self.class}#to_yaml method must be implemented"
end
|